
2 Oct
2003
2 Oct
'03
12:57 p.m.
On Thu, 02 Oct 2003 14:27:29 +0200
"Marcin 'Qrczak' Kowalczyk"
Accumulating state is fine. These definitions don't accumulate state: 'return' should yield a "neutral" state, and the above ">>=" ignores the state of the lhs.
You're right.
data Accum s a = Ac [s] a
instance Monad (Accum s) where return x = Ac [] x Ac s1 x >>= f = let Ac s2 y = f x in Ac (s1++s2) y
output :: a -> Accum a () output x = Ac [x] ()
Nice. Thanks! Juanma