[Haskell-cafe] Problem with monad transformer stack

Bryan O'Sullivan bos at serpentine.com
Sun Oct 3 22:06:03 EDT 2010


On Sun, Oct 3, 2010 at 9:40 PM, Michael Vanier <mvanier42 at gmail.com> wrote:

>
> {- This doesn't work: -}
> newtype MyMonad a =
>  MyMonad ((StateT (MyData a) (Either SomeError) a))
>  deriving (Monad,
>            MonadState (MyData a),
>            MonadError SomeError,
>            Typeable)
>

This simply isn't allowed by the generalised newtype derivation machinery,
because the type variable "a" appears in one of the classes you're deriving.

In fact, I'm not sure how you're hoping for your type to actually work as a
monad. If you try using (>>=) on your type synonym that currently appears to
typecheck, you'll find that the only value that can inhabit the state
parameter is bottom. Try writing out and using a definition of (>>=) by hand
to understand your confusion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101003/63aa31cb/attachment.html


More information about the Haskell-Cafe mailing list