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 ;-)
> I used to think about a physical engine in a similar way, and I thinkThis is something handled best by functional reactive programming. See
> 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?
Peter Verswyvelen's post. It allows you to encode this purely in an
excitingly elegant way.
You don't. Either you use a state monad to hold _all_ wires (objects)
> 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?
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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe