[Haskell-beginners] EitherT

Francesco Ariis fa-ml at ariis.it
Thu Apr 12 15:59:32 UTC 2018


On Thu, Apr 12, 2018 at 11:25:57AM +0100, mike h wrote:
> This is what I have
> 
> newtype EitherT m a b = EitherT {runEitherT :: m (Either a b)}
> instance Monad m => Functor (EitherT m a) where
>     ---- fmap :: (a -> b) -> f a -> f b
>     fmap f m = EitherT $ do
>         mv <- runEitherT m
>         case mv of
>             Left _   -> return mv
>             Right rv -> return $ Right (f rv)

Tricky error! The signature for this fmap is:

    fmap :: (b -> c) -> EitherT m a b -> EitherT m a c

The offending line is:

    Left _   -> return mv

You *think* you are returning `Either a c`, but are you really?

Type HINTS for more :P
-F


More information about the Beginners mailing list