es at ertes.de
Thu Sep 20 04:56:05 CEST 2012
Miguel Negrao <miguel.negrao-lists at friendlyvirus.org> wrote:
> > Netwire follows a more algebraic path and drops the classic notion.
> > The line between signals and events is blurred. It's a bit more
> > difficult to understand, but is more expressive and concise. Also
> > it's pretty much time-leak-free. The library is designed to be very
> > elegant while preserving non-FRP performance to a high degree.
> > (To be fair, I'm the author of Netwire.) =)
> Having recently looked a bit on Yampa, what are the main differences
> between Yampa and Netwire ?
The way events are handled. Yampa uses the classic automaton category
with an additional time delta argument for its signal function
representation (Yampa's type is more complicated, but isomorphic to this
type Time = Double
newtype SF a b = SF (Time -> a -> (b, SF a b))
Netwire generalizes this category to a class of wire categories
(simplified and without associated types):
newtype Wire e a b = Wire (Time -> a -> (Either e b, Wire e a b))
SF is an arrow and an applicative functor (although Yampa does not
provide an Applicative instance). Wire is also an Alternative, which
allows concise and efficient switching with very little cruft. The
following wire renders "yes" when the "keyDown Space" event happens and
pure "yes" . keyDown Space <|> pure "no"
Or with the OverloadedStrings extension:
"yes" . keyDown Space <|> "no"
All classic (non-wire) FRP implementations need switching or another
ad-hoc combinator for this. If you happen to need switching it's also a
lot simpler using wires:
"please press space" . notE (keyDown Space) --> "thanks"
This one waits for the Space key and then outputs "thanks" forever. So
far Netwire has the fastest and most elegant way of dealing with events
compared to all other libraries I have tried.
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...
Size: 836 bytes
Desc: not available
More information about the Beginners