Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Confused by GLFW and more (Britt Anderson)
2. Re: Confused by GLFW and more (Felipe Almeida Lessa)
3. Re: Confused by GLFW and more (Britt Anderson)
4. Re: Confused by GLFW and more (Daniel Fischer)
5. Re: Confused by GLFW and more (Felipe Almeida Lessa)
----------------------------------------------------------------------
Message: 1
Date: Thu, 3 Mar 2011 10:34:32 -0500
From: Britt Anderson <[email protected]>
Subject: [Haskell-beginners] Confused by GLFW and more
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
To: Beginners List
I am trying to get a simple program working that will display
something on the screen, get user input via joystick until a quit
event, and then start a new trial, and repeat this until all the
trials have been performed.
The problem is that if I try to sequence the trials it hangs on the
last trial (screen freezes and I have to kill it), however, if I just
execute one after the other it exits fine. I don't understand what is
different about doing the commented line versus explicitly invoking
two trials (as demonstrated in the snippet below).
Here is a snippet ( I am happy to provide more, but I don't know what
is needed to diagnose my problem and I don't want to clutter the
question):
tn = 3
main :: IO ()
main = do
let ps = initPlayers
createWindow
putStr "Window Initialized\n"
let joy = GLFW.Joystick 1
putStr "Got Joystick\n"
--sequence_ $ map (trialLoop gain tolerance joy) (trialList ps)
trialLoop gain tolerance joy ((trialList ps)!!0)
trialLoop gain tolerance joy ((trialList ps)!!1)
putStr "Back from Sequence\n"
where trialList oldps =
[[(h' i) , (p' i)] | i <- [1 ..], i < tn]
where
x = 0.2
y = 0.2
h' idx = (oldps!!0)
p' idx = Prey (Circle (((-1)^idx)*0.2,0.2) ((radius .
shape) (oldps!!1))) (clr $ oldps!!1)
As an aside, I was wondering if anyone has experience using joysticks
with any of the Graphics.UI I have both a logitech and a saitek and I
find that although both are found by the Graphics.UI.SDL I cannot get
the buttons for the Saitek, but can for logitech. For neither does
pollEvents seem to work right, although I can use update and getAxis
for both joysticks. It was this unpredictable behaviour that drove me
from SDL to GLFW.
Any general advice on the UIs for joysticks would be appreciated as
well. I am not actually writing a game, but a simple psychophysics
experiment (the use of Haskell is just an exercise - normally I would
do this [and have been done with it long ago] in python. So, my
questions are really focused on trying to use haskell and its
libraries for this purpose). Using Arch Linux if that makes any
difference.
Thanks in advance for any comments.
--Britt
------------------------------
Message: 2
Date: Thu, 3 Mar 2011 15:59:12 +0000
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Confused by GLFW and more
To: Britt Anderson <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Mar 3, 2011 at 3:34 PM, Britt Anderson
<[email protected]> wrote:
> ?--sequence_ $ map (trialLoop gain tolerance joy) (trialList ps)
> ?trialLoop gain tolerance joy ((trialList ps)!!0)
> ?trialLoop gain tolerance joy ((trialList ps)!!1)
First of all, instead of "sequence_ $ map ..." use "mapM_ ...", which
is the same thing but nicer.
Now, have you tried "mapM_ (trialLoop gain tolerance joy) (take 2 $
trialList ps)"? That should be the same as those two lines you wrote.
I am suspecting here that your program is hanging only with mapM_
because of some of the trials that are not the first two.
HTH,
--
Felipe.
------------------------------
Message: 3
Date: Thu, 3 Mar 2011 11:40:52 -0500
From: Britt Anderson <[email protected]>
Subject: Re: [Haskell-beginners] Confused by GLFW and more
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
This does fix the problem. Thank you. But raises a new question. Since
that list was being constructed like this
where trialList oldps =
[[(h' i) , (p' i)] | i <- [1 ..], i < tn]
it should have only had two elements when tn = 3. So, I assume that I
am getting hit by a laziness issue, but how is it that I should have
known that using mapM_ wouldn't have force thelist to exist in a
finite form?
By the way, I just now use "take (tn -1)" and all is good, but I would
like to understand this issue better so I can avoid similar pitfalls
in the future.
Thx, Britt
On Thu, Mar 3, 2011 at 10:59 AM, Felipe Almeida Lessa
<[email protected]> wrote:
> On Thu, Mar 3, 2011 at 3:34 PM, Britt Anderson
> <[email protected]> wrote:
>> ?--sequence_ $ map (trialLoop gain tolerance joy) (trialList ps)
>> ?trialLoop gain tolerance joy ((trialList ps)!!0)
>> ?trialLoop gain tolerance joy ((trialList ps)!!1)
>
> First of all, instead of "sequence_ $ map ..." use "mapM_ ...", which
> is the same thing but nicer.
>
> Now, have you tried "mapM_ (trialLoop gain tolerance joy) (take 2 $
> trialList ps)"? ?That should be the same as those two lines you wrote.
> ?I am suspecting here that your program is hanging only with mapM_
> because of some of the trials that are not the first two.
>
> HTH,
>
> --
> Felipe.
>
------------------------------
Message: 4
Date: Thu, 3 Mar 2011 18:13:35 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Confused by GLFW and more
To: [email protected]
Cc: Britt Anderson <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 03 March 2011 17:40:52, Britt Anderson wrote:
> This does fix the problem. Thank you. But raises a new question. Since
> that list was being constructed like this
>
> where trialList oldps =
> [[(h' i) , (p' i)] | i <- [1 ..], i < tn]
>
where trialList oldps =
[[h' i, p' i] | i <- takeWhile (< tn) [1 .. ]]
The probem is that the compiler can't know that i never gets smaller than
tn again once the first i >= tn is reached?, so it is busy generating ever
larger integers and testing them against tn, never finishing (well, it will
finish when i is large enough to blow your memory, perhaps when
i >= 2^(2^31) on a 32-bit system, I don't know how overflow of Integer is
handled)
? An instance of Enum and Ord may wrap around, although that would be
against the spirit of those two classes.
>
>
> it should have only had two elements when tn = 3. So, I assume that I
> am getting hit by a laziness issue, but how is it that I should have
> known that using mapM_ wouldn't have force thelist to exist in a
> finite form?
Laziness only in so far as it's necessary for [1 .. ]. The issue has
nothing to do with monads or mapM_, it's the fact that the compiler doesn't
use 'rules that should hold for instances of ...' and hence has to try on
after a human knows it's over.
>
> By the way, I just now use "take (tn -1)" and all is good, but I would
> like to understand this issue better so I can avoid similar pitfalls
> in the future.
A similar pit is often fallen into with filter.
>
> Thx, Britt
------------------------------
Message: 5
Date: Thu, 3 Mar 2011 17:18:34 +0000
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Confused by GLFW and more
To: Daniel Fischer <[email protected]>
Cc: [email protected], Britt Anderson <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Mar 3, 2011 at 5:13 PM, Daniel Fischer
<[email protected]> wrote:
> On Thursday 03 March 2011 17:40:52, Britt Anderson wrote:
>> This does fix the problem. Thank you. But raises a new question. Since
>> that list was being constructed like this
>>
>> ?where trialList oldps =
>> ? ? ? ? ? [[(h' i) , (p' i)] | i <- [1 ..], i < tn]
>>
>
> where trialList oldps =
> ? ?[[h' i, p' i] | i <- takeWhile (< tn) [1 .. ]]
>
> The probem is that the compiler can't know that i never gets smaller than
> tn again once the first i >= tn is reached?, so it is busy generating ever
> larger integers and testing them against tn, never finishing (well, it will
> finish when i is large enough to blow your memory, perhaps when
> ?i >= 2^(2^31) on a 32-bit system, I don't know how overflow of Integer is
> handled)
And the fix would be to code as
where trialList oldps =
[[h' i, p' i] | i <- [1..tn]]
PS: Why aren't you using a tuple? =)
--
Felipe.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 33, Issue 4
****************************************