<div><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">Try to unify the types returned by each of the case alternatives, starting from what the compiler has inferred so far.</div><div dir="auto"><br></div><div dir="auto">I’ve made this mistake many times lol.</div><div dir="auto"><br></div><div dir="auto">Best,</div><div dir="auto"><br></div><div dir="auto">toz </div><br><div class="gmail_quote"><div>On Thu, Apr 12, 2018 at 5:38 AM <<a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send Beginners mailing list submissions to<br>
        <a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:beginners-request@haskell.org" target="_blank">beginners-request@haskell.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:beginners-owner@haskell.org" target="_blank">beginners-owner@haskell.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Beginners digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1.  EitherT (mike h)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 12 Apr 2018 11:25:57 +0100<br>
From: mike h <<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>><br>
To: The Haskell-Beginners Mailing List - Discussion of primarily<br>
        beginner-level topics related to Haskell <<a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a>><br>
Subject: [Haskell-beginners] EitherT<br>
Message-ID: <<a href="mailto:57AFC9F5-3601-4D18-B860-41352D3F2204@yahoo.co.uk" target="_blank">57AFC9F5-3601-4D18-B860-41352D3F2204@yahoo.co.uk</a>><br>
Content-Type: text/plain; charset=utf-8<br>
<br>
Hi,<br>
I’m trying to write EitherT from first principles and I’m stuck at the first hurdle - Functor.  I’m looking for a hint rather than a complete answer :) <br>
<br>
<br>
This is what I have<br>
<br>
newtype EitherT m a b = EitherT {runEitherT :: m (Either a b)}<br>
instance Monad m => Functor (EitherT m a) where<br>
    ---- fmap :: (a -> b) -> f a -> f b<br>
    fmap f m = EitherT $ do<br>
        mv <- runEitherT m<br>
        case mv of<br>
            Left _   -> return mv<br>
            Right rv -> return $ Right (f rv)<br>
<br>
<br>
<br>
and here is the compilers view<br>
Phrase.hs:31:25: error:<br>
    • Couldn't match type ‘b’ with ‘a1’<br>
      ‘b’ is a rigid type variable bound by<br>
        the type signature for:<br>
          fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b<br>
        at Phrase.hs:27:5-8<br>
      ‘a1’ is a rigid type variable bound by<br>
        the type signature for:<br>
          fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b<br>
        at Phrase.hs:27:5-8<br>
      Expected type: m (Either a a1)<br>
        Actual type: m (Either a b)<br>
    • In the expression: return $ Right (f rv)<br>
      In a case alternative: Right rv -> return $ Right (f rv)<br>
      In a stmt of a 'do' block:<br>
        case mv of<br>
          Left _ -> return mv<br>
          Right rv -> return $ Right (f rv)<br>
    • Relevant bindings include<br>
        rv :: a1 (bound at Phrase.hs:31:19)<br>
        mv :: Either a a1 (bound at Phrase.hs:28:9)<br>
        m :: EitherT m a a1 (bound at Phrase.hs:27:12)<br>
        f :: a1 -> b (bound at Phrase.hs:27:10)<br>
        fmap :: (a1 -> b) -> EitherT m a a1 -> EitherT m a b<br>
          (bound at Phrase.hs:27:5)<br>
<br>
<br>
what I think I need to do is fmap over the right value after pulling if out of the monad m by doing   mv <- runEitherT m<br>
<br>
these lines from the compiler are particularly confusing <br>
      Expected type: m (Either a a1)<br>
        Actual type: m (Either a b)<br>
<br>
as I believe f is    f:: a1->b <br>
<br>
So just hints please and I expect I’ll have another duh moment. <br>
<br>
Thanks<br>
<br>
Mike<br>
<br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br>
<br>
------------------------------<br>
<br>
End of Beginners Digest, Vol 118, Issue 6<br>
*****************************************<br>
</blockquote></div></div>