[Haskell-cafe] Stacking StateTs

David Menendez dave at zednenem.com
Sun Feb 22 12:53:08 EST 2009


On Sun, Feb 22, 2009 at 9:20 AM, Luis O'Shea <loshea at gmail.com> wrote:
>> test3 :: MonadState Integer m => String -> m String
>
> Good point.  It's interesting that this allows the signature of test5b to
> become MonadState Integer m => m Integer (instead of (Monad m) => StateT
> Integer (StateT String m) Integer) which is more general, and (surprisingly
> to me) does not mention String.

Odd. If I break up test5b like so:

test5b = flip execStateT 0 . flip evalStateT "" $ test5bImpl

test5bImpl = do
	modifyM test3
	lift . modify $ \x -> x*2 + 1
	modifyM test3
	lift . modify $ \x -> x*x
	modifyM test3

and ask GHCi for the types, I get:

*Main> :t test5bImpl
test5bImpl :: (MonadState Integer m) => StateT String m ()
*Main> :t test5b
test5b :: (Monad m) => m Integer



-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list