[Haskell-cafe] Infinite lists in real world programs
limestrael at gmail.com
Wed Dec 15 14:52:11 CET 2010
I was wondering if using infinite lists was a viable and efficient solution
in haskell programs (I mean not simple prototypes) :
I was considering using them to model agents in a hierarchical multi-agent
application for school.
A list would representate the state of an agent at a step of the program.
Let's say we have two simple agents, one multiplying its input by 2 and the
other dividing it by 4 :
agent1 = fmap (*2)
agent2 = fmap (/4)
allValues = xs where
ys = agent1 xs
xs = 100:agen2 ys
main = do
mapM_ print $ take 100 allValues
Of course, in a real program, an agent would rather take a list of multiple
agents (i.e. a list of lists) in input, so that its ouput could depend on
what several agents feed him.
Some could state what I'm trying to do is FRP, and I agree. But it remains a
simple goal so I'd like to keep the program simple, and not go into the
whole complexity of a FRP framework (and I'm working with a non-haskeller).
For instance, with my solution, I cannot dynamically connect or disconnect
agents during the runtime, but I'll will not need to do that in my program.
Besides, I'd like to try to implement this myself, not use an already
So is it viable or would the use of multiple infinite lists kill the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe