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. Re: firering event in netwire (Nathan H?sken)
2. Re: firering event in netwire (Ertugrul S?ylemez)
3. Re: firering event in netwire (Nathan H?sken)
4. Re: firering event in netwire (Ertugrul S?ylemez)
5. computing percentile (Dennis Raddle)
6. Re: computing percentile (Nick Vanderweit)
7. Re: FRP (Miguel Negrao)
8. Re: computing percentile (Dennis Raddle)
----------------------------------------------------------------------
Message: 1
Date: Mon, 01 Oct 2012 13:31:04 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 09/30/2012 05:39 AM, Ertugrul S?ylemez wrote:
> However, I rather recommend against passing multiple SDL events at once.
> Wires can handle individual events much better and, when properly
> designed, also faster.
Ok, so I update my wire on every event I receive. That way I only have
one event for every wire update.
Now I want my state updates frame based, not time based. I am trying to
update the state based on the NoEvent event (the main look takes care
that this happens in an constant interval).
I have an Event Wire
isKeyPressed code :: EventP SDL.Event"
which produces when the key is pressed and inhibits when it is not pressed.
speed = (((pure (-1.0)) . isKeyPressed leftKeyCode) <|> pure 0.0)
+
(((pure 1.0) . isKeyPressed rightKeyCode) <|> pure 0.0)
So speed is -1 if the left key is pressed, +1 if the right key is
pressed and 0 if none or both are pressed.
Now I want to integrate this speed (frame based):
pos = accum (+) . speed
But this does not do the accumulation every frame, but whenever an event
happens.
So I would need a "require (==NoEvent)" somewhere. But I do not see
where I could put it to archive the desired behavior.
I am not sure if I am using netwire correctly.
Thanks & Regards,
Nathan
------------------------------
Message: 2
Date: Mon, 1 Oct 2012 13:58:34 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Nathan H?sken <[email protected]> wrote:
> Now I want my state updates frame based, not time based. I am trying
> to update the state based on the NoEvent event (the main look takes
> care that this happens in an constant interval).
With Netwire you can have your own time frame. For example you can just
call stepWire with a constant dt or you can use the counterSession.
> I have an Event Wire
>
> isKeyPressed code :: EventP SDL.Event"
>
> which produces when the key is pressed and inhibits when it is not
> pressed.
>
> speed = (((pure (-1.0)) . isKeyPressed leftKeyCode) <|> pure 0.0)
> +
> (((pure 1.0) . isKeyPressed rightKeyCode) <|> pure 0.0)
Let me rewrite this to make it slightly more pleasing to the eye:
speed = ((-1) . isKeyPressed leftKeyCode <|> 0) +
(1 . isKeyPressed rightKeyCode <|> 0)
> So speed is -1 if the left key is pressed, +1 if the right key is
> pressed and 0 if none or both are pressed.
>
> Now I want to integrate this speed (frame based):
>
> pos = accum (+) . speed
This should be a type error. Rather:
pos = accum (+) initialPos . speed
> But this does not do the accumulation every frame, but whenever an
> event happens.
That wire by itself does the accumulation at every frame, so you
probably have an inhibiting wire earlier in the chain.
Greets,
Ertugrul
--
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121001/16f5973a/attachment-0001.pgp>
------------------------------
Message: 3
Date: Mon, 01 Oct 2012 14:12:11 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 10/01/2012 01:58 PM, Ertugrul S?ylemez wrote:
>> Now I want to integrate this speed (frame based):
>>
>> pos = accum (+) . speed
>
> This should be a type error. Rather:
>
> pos = accum (+) initialPos . speed
>
>
Yes of course.
>> But this does not do the accumulation every frame, but whenever an
>> event happens.
>
> That wire by itself does the accumulation at every frame, so you
> probably have an inhibiting wire earlier in the chain.
Let me restate my problem. My wire is this:
pos = accum (+) 0.0 . speed
and all I do is putStrLn the output at every frame.
If withing one frame where speed has the value (1) several events are
sent over the wire (for example several keyup and keydown events for an
unrelated key), then pos gets incremented for one for each of this
events. So I have to prevent the accumulation if the event is not NoEvent.
Regards,
Nathan
------------------------------
Message: 4
Date: Mon, 1 Oct 2012 14:22:38 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Nathan H?sken <[email protected]> wrote:
> >> But this does not do the accumulation every frame, but whenever an
> >> event happens.
> >
> > That wire by itself does the accumulation at every frame, so you
> > probably have an inhibiting wire earlier in the chain.
>
> Let me restate my problem. My wire is this:
>
> pos = accum (+) 0.0 . speed
>
> and all I do is putStrLn the output at every frame.
As a side note, see testWire and testWireM in Control.Wire.Session. =)
> If withing one frame where speed has the value (1) several events are
> sent over the wire (for example several keyup and keydown events for
> an unrelated key), then pos gets incremented for one for each of this
> events. So I have to prevent the accumulation if the event is not
> NoEvent.
That's because you're using constant time deltas. Even if your time
frame has a constant rate you should still make use of your time deltas.
In particular notice that Netwire can deal with time deltas of 0. Then
instead of accum you would use integral_.
Greets,
Ertugrul
--
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121001/7323fe03/attachment-0001.pgp>
------------------------------
Message: 5
Date: Mon, 1 Oct 2012 15:11:40 -0700
From: Dennis Raddle <[email protected]>
Subject: [Haskell-beginners] computing percentile
To: Haskell Beginners <[email protected]>
Message-ID:
<cakxlvoo4rkjywjawr0w_btiqjbgtj1xe4xldjbqoprmngzp...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Just thought I would toss the list a problem I need to solve and see what I
can learn from the solutions here.
My problem is that I need to take a list of Double and map them into
"percentile" form (not sure if I have that terminology correct) - so that
the lowest number is mapped to 0, the highest number is mapped to 1, the
median is mapped to 0.5, and in general given a fixed delta D and an
interval (x, x +D) in the percentile domain, the same number of elements
get mapped into that interval for any x. Except there aren't an infinity of
values and there may be ties, so it gets a little fuzzier how to define it.
so I need:
toPercentile :: [Double] -> [Double]
I shall now work on it and report back.
Dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121001/16c9ed0a/attachment-0001.htm>
------------------------------
Message: 6
Date: Mon, 01 Oct 2012 17:28:20 -0600
From: Nick Vanderweit <[email protected]>
Subject: Re: [Haskell-beginners] computing percentile
To: [email protected]
Message-ID: <3793170.3eGlgxvdJc@euler>
Content-Type: text/plain; charset="us-ascii"
Here is my implementation, which sorts the list of values. If there are N
values, the first gets a percentile of 0/N, the second gets 1/N, and so on, so
that the last value gets a percentile of (N-1)/N. It then generates the
percentiles list from this mapping.
import Data.List (sort)
import Data.Maybe (fromJust)
toPercentile xs =
let pairs = zip (sort xs) .
map (/(fromIntegral $ length xs)) . map fromInteger $ [0..]
in map (fromJust . (flip lookup) pairs) xs
Nick
On Monday, October 01, 2012 03:11:40 PM Dennis Raddle wrote:
> Just thought I would toss the list a problem I need to solve and see what I
> can learn from the solutions here.
>
> My problem is that I need to take a list of Double and map them into
> "percentile" form (not sure if I have that terminology correct) - so that
> the lowest number is mapped to 0, the highest number is mapped to 1, the
> median is mapped to 0.5, and in general given a fixed delta D and an
> interval (x, x +D) in the percentile domain, the same number of elements
> get mapped into that interval for any x. Except there aren't an infinity of
> values and there may be ties, so it gets a little fuzzier how to define it.
>
> so I need:
>
> toPercentile :: [Double] -> [Double]
>
> I shall now work on it and report back.
>
> Dennis
------------------------------
Message: 7
Date: Tue, 2 Oct 2012 00:50:42 +0100
From: Miguel Negrao <[email protected]>
Subject: Re: [Haskell-beginners] FRP
To: Heinrich Apfelmus <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
A 01/10/2012, ?s 09:49, Heinrich Apfelmus escreveu:
> Miguel Negrao wrote:
>> Thanks for the explanation. I was wondering, how would one translate
>> this Yampa code into reactive-banana:
>> fallingBall :: Pos -> Vel -> SF () (Pos, Vel)
>> fallingBall y0 v0 = proc () -> do
>> v <- (v0 +) ?<< integral -< -9.81
>> y <- (y0 +) ?<< integral -< v
>> returnA -< (y, v)
>> fallingBall? :: Pos -> Vel -> SF () ((Pos,Vel), Event (Pos,Vel))
>> fallingBall? y0 v0 = proc () -> do
>> yv@(y, _) <- fallingBall y0 v0 -< ()
>> hit <- edge -< y <= 0
>> returnA -< (yv, hit ?tag? yv)
>> bouncingBall :: Pos -> SF () (Pos, Vel)
>> bouncingBall y0 = bbAux y0 0.0
>> where
>> bbAux y0 v0 = switch (fallingBall? y0 v0) $ \(y,v) -> bbAux y
>> (-v)
>> Would it be possible to do this without dynamic event switching ?
>> What about with the new event switching in v0.7 ? Also, is it possible (and
>> is it easy ?) to do looping such as it is done in Yampa using the the
>> loop arrow in reactive-banana/classic FRP ?
>
> The Animation.hs example may help
>
> http://www.haskell.org/haskellwiki/Reactive-banana/Examples#animation
>
> Essentially, the main difference is that reactive-banana doesn't have
> functions like integral or edge because they depend on an implicit time
> step. In reactive-banana, you have to manage time yourself, for instance by
> making a timer event from a wxTimer.
>
> To calculate velocity and position, you can you use accumE on the timer
> event. To do collision detection, you can check whether the ball will move
> below the floor at each time step. Dynamic event switching is not needed here.
>
> For a more complex example, have a look at Andreas Bernstein's paddle ball
> game
>
> https://github.com/bernstein/breakout
Yes, looking at the internals of Yampa I had seen that they have internal time
management, but my question was more specifically if there was a way to have a
function like bbAux which recursively switches into itself. Would it be
possible with the new dynamic switching ? I find that way of expressing the
discontinuous changes quite elegant. Even more elegant seems to be the
instantaneous impulses (modeling of distributions or dirac deltas) although I
couldn?t find any functioning code that implements it [1].
The breakout game code you mentioned is an excelent example of FRP in use, and
best of all, it actually compiles !! I?ve lost count of the FRP programs I?ve
tried to compile without success (mostly yampa or YFRP related). It was very
instructional to see how it implements this kind of game logic in
reactiva-banana. It?s also a good example of recursive definitions in
reactiva-banana: the ball velocity depends on the ball position and vice-versa.
Thank you for the link and the explanations,
Miguel
[1]
http://haskell.cs.yale.edu/wp-content/uploads/2011/01/icfp03.pdf
bouncing :: Position -> SF () (Position, Velocity)
bouncing y0 = proc () -> do rec
y <- (y0 +) ^<< integralG -< yd_ni
hit <- edge -< y <= 0
yd <- integralG -< -9.81 + impulse (hit ?tag? (-2*leftLimit yd))
yd_ni <- assertNoImpulseG -< yd
returnA -< (y, yd)
------------------------------
Message: 8
Date: Mon, 1 Oct 2012 20:05:59 -0700
From: Dennis Raddle <[email protected]>
Subject: Re: [Haskell-beginners] computing percentile
To: Haskell Beginners <[email protected]>
Message-ID:
<cakxlvoo6+9tgztkrl_-tceasuvkgu8ateyhy4wzv8nxw4l7...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I'm not sure if you considered duplicate elements. I came up with this
(which handles duplicates by averaging the percentile position of the first
index of the element in the sorted list and the last index of the element.
How one handles duplicates may be arbitrary or dependent on the deeper
problem). Also for my problem I wanted the maximum percentile to be 1
rather than (N-1)/N but that may just depend on your definition.
import qualified Data.List as L
toPercentile inp = map doValue inp
where
sorted = L.sort inp
len = length inp
perc idx = fromIntegral idx / (fromIntegral len - 1)
doValue x = case L.elemIndices x sorted of
[i] -> perc i
is -> ((perc (head is)) + (perc (last is)))/2
On Mon, Oct 1, 2012 at 4:28 PM, Nick Vanderweit
<[email protected]>wrote:
> Here is my implementation, which sorts the list of values. If there are N
> values, the first gets a percentile of 0/N, the second gets 1/N, and so
> on, so
> that the last value gets a percentile of (N-1)/N. It then generates the
> percentiles list from this mapping.
>
> import Data.List (sort)
> import Data.Maybe (fromJust)
> toPercentile xs =
> let pairs = zip (sort xs) .
> map (/(fromIntegral $ length xs)) . map fromInteger $ [0..]
> in map (fromJust . (flip lookup) pairs) xs
>
>
> Nick
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121001/bef0af87/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 52, Issue 2
****************************************