hello,
i am having
trouble getting my program below to work.
i think i
implemented the monad methods correctly, but
the function
'g' does not type as i would expect. Hugs
thinks that
it is just a list (if i remove the explicit
typing). i
want it to be functionally identical to the
function
'h'.
what am i
missing?
thanks
konst
> newtype
State s a = ST (s -> (a,s))
>
> unST
(ST m) = m
>
>
instance Functor (State s) where
> fmap f m = ST (\s
-> let (a,s') = unST m s in (f a, s'))
>
>
instance Monad (State s) where
> return a = ST (\s
-> (a,s))
> m >>= f = ST (\s -> let
(a,s') = unST m s in unST (f a) s')
>
> --g ::
State String Char
> g = [ x | x <- return 'a' ]
>
> h ::
State String Char
> h = return 'a'