Newbie qustion about monads
Juanma Barranquero
jmbarranquero at laley.wke.es
Thu Oct 2 15:57:22 EDT 2003
On Thu, 02 Oct 2003 14:27:29 +0200
"Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> wrote:
> 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
More information about the Haskell-Cafe
mailing list