[Haskell-cafe] Re: simulation in the haskell way

Peter Verswyvelen bugfact at gmail.com
Tue Aug 18 19:41:10 EDT 2009

It is interesting to note that recent work on AFRP (arrow-based FRP) -
namely "Causal Commutative Arrows" -  optimizes a complete circuit of arrows
("interconnected objects" if you prefer to think that way) that all have
local state and local feedback loops into one large state and feedback loop,
 essentially what optimized imperative simulations also do (e.g. thousands
of moving particles that are treated as a single state block of
position/velocity pairs). Together with stream fusion the researchers
working on this were able to generate optimized code that runs hundreds
(!!!) times faster than the best GHC could do. Impressive isn't it.
Unfortunately it will only work on static networks, not those with dynamic
switches in it, but I'm pretty sure that within say 5 years, this will all
be settled and it will become exiting times for simulation developers, we
will finally be pure, lazy *and* fast; it just needs a little push (since
it's now mostly pulling, okay I'll stop the nonsense, couldn't resist the
nerd talk ;-)
On Wed, Aug 19, 2009 at 1:29 AM, Ertugrul Soeylemez <es at ertes.de> wrote:

> Eric Wong <wsysdu at gmail.com> wrote:
> > I used to think about a physical engine in a similar way, and I think
> > it can work. But in some simulations that objects have lots of
> > dependencies on others can be tricky. For instance, object o1 depends
> > on o2, if we represent them in pure values, when we update o2, then o1
> > must be updated with a new o2 value, isn't it?
> This is something handled best by functional reactive programming.  See
> Peter Verswyvelen's post.  It allows you to encode this purely in an
> excitingly elegant way.
> > Recently I want to implement the digital circuit simulation in SICP
> > using Haskell as an exercise. In the Scheme version, each Wire is
> > represented as a function with local states. It records the signal on
> > the wire and actions it will take when the signal changes to activate
> > other wires.  How to represent the Wire in haskell purely?
> >
> > If I use State Monad (yes, it's pure :) to repsent a wire with local
> > state, the interaction between connected wires is really tricky to
> > implement.  any ideas?
> You don't.  Either you use a state monad to hold _all_ wires (objects)
> in, say, a Map, a Set or an Array, or you use a completely different
> approach (like FRP).  In other words, your state monad should represent
> all wires, not just one, because all wires together make up the state
> you want to work with.
> Greets,
> Ertugrul.
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://blog.ertes.de/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090818/cf6f412c/attachment.html

More information about the Haskell-Cafe mailing list