[Haskell-cafe] Stacking StateTs

Felipe Lessa felipe.lessa at gmail.com
Sun Feb 22 13:29:49 EST 2009


On Sun, Feb 22, 2009 at 3:17 PM, Daniel Fischer
<daniel.is.fischer at web.de> wrote:
> test5b :: (Monad (StateT [Char] (StateT s m)),
>           MonadState s (StateT s m),
>           Num s,
>           Monad m) =>
>          m s

Doesn't 'Monad m' imply 'MonadState s (StateT s m)' which implies
'Monad (StateT s m)' which implies 'Monad (StateT [Char] (StateT s
m))'? This signature could be simplified to just

test5b :: (Num s, Monad m) => m s

> test5bImpl :: (Monad (StateT [Char] m), MonadState s m, Num s) =>
>              StateT [Char] m ()

Here 'MonadState s m' implies 'Monad m' which implies 'Monad (StateT
[Char] m)', simplifying the signature to

test5bImpl :: (Num s, MonadState s m) => StateT [Char] m ()

Now, note that Menendez' signatures didn't have 'Num s' because a type
signature was given to 'test3' forcing the number to be Integer. If
you remove all type signatures (and the monomorphism restriction), GHC
6.10 infers

modifyM :: (Monad m) => (s -> m s) -> StateT s m ()
test3 :: (Num s, MonadState s m) => [Char] -> m [Char]
test5b :: (Num b, Monad m) => m b
test5b' :: (Num b, Monad m) => m b
impl :: (Num s, MonadState s m) => StateT [Char] m ()

Did I make any mistakes?

-- 
Felipe.


More information about the Haskell-Cafe mailing list