[Haskell-cafe] Infinite lists in real world programs
limestrael at gmail.com
Thu Dec 16 18:52:58 CET 2010
Okay, I started to experiment things, and I came to some remarks:
First, I cannot use bare lists, because of the way their Applicative
instance is declared.
I have to use the newtype ZipList (in Control.Applicative).
So I have roughly this :
newtype AgentSig a = AgentSig (ZipList a)
deriving (Functor, Applicative)
(<+>) :: a -> AgentSig a -> AgentSig a
v <+> (AgentSig (ZipList sig)) = AgentSig . ZipList $ v:sig
toList :: AgentSig a -> [a]
toList (AgentSig (ZipList sig)) = sig
fromList :: [a] -> AgentSig a
fromList = AgentSig . ZipList
This enables me to do things like :
agent3 a b = (/) <$> a <*> b
run = z
where x = agent1 y
y = 100 <+> agent2 x
z = agent3 x y
One problem though: How to make an instance of Monad out of AgentSig?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe