
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'

Konst Sushenko writes: | what am i missing? : | > --g :: State String Char | > g = [ x | x <- return 'a' ] Hi. The comprehension syntax used to be for monads in general (in Haskell 1.4-ish), but is now (Haskell 98) back to being specific to lists. Does it help if you use do-notation instead? Regards, Tom
participants (2)
-
Konst Sushenko
-
Tom Pledger