Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  EitherT (Francesco Ariis)
   2. Re:  EitherT (David McBride)
   3. Re:  EitherT (鲍凯文)
   4. Re:  EitherT (mike h)


----------------------------------------------------------------------

Message: 1
Date: Thu, 12 Apr 2018 17:59:32 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] EitherT
Message-ID: <20180412155932.r5fbeh5wn52k4...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

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


------------------------------

Message: 2
Date: Thu, 12 Apr 2018 12:27:30 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] EitherT
Message-ID:
        <can+tr41enxtvb8dyvrxtcwc+3kojbyfus6dfogbtg4f0k7w...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You will feel like this was obvious in hindsight.

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

Now follow the types in your code.
m :: EitherT m c a
mv :: Either c a
return mv :: EitherT m c a -- <- you are back to the wrong type.

How can you instead return EitherT m c b?


On Thu, Apr 12, 2018 at 6:25 AM, mike h <mike_k_hough...@yahoo.co.uk> wrote:

> Hi,
> 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 :)
>
>
> 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)
>
>
>
> and here is the compilers view
> Phrase.hs:31:25: error:
>     • Couldn't match type ‘b’ with ‘a1’
>       ‘b’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       ‘a1’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
>     • In the expression: return $ Right (f rv)
>       In a case alternative: Right rv -> return $ Right (f rv)
>       In a stmt of a 'do' block:
>         case mv of
>           Left _ -> return mv
>           Right rv -> return $ Right (f rv)
>     • Relevant bindings include
>         rv :: a1 (bound at Phrase.hs:31:19)
>         mv :: Either a a1 (bound at Phrase.hs:28:9)
>         m :: EitherT m a a1 (bound at Phrase.hs:27:12)
>         f :: a1 -> b (bound at Phrase.hs:27:10)
>         fmap :: (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>           (bound at Phrase.hs:27:5)
>
>
> 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
>
> these lines from the compiler are particularly confusing
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
>
> as I believe f is    f:: a1->b
>
> So just hints please and I expect I’ll have another duh moment.
>
> Thanks
>
> Mike
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180412/05fe8014/attachment-0001.html>

------------------------------

Message: 3
Date: Thu, 12 Apr 2018 16:40:53 +0000
From: 鲍凯文 <traqueofzi...@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] EitherT
Message-ID:
        <CAMjcG+Go=Uk==ur+nxyxopscsnywzgg15nngtnnfioifex3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

Try to unify the types returned by each of the case alternatives, starting
from what the compiler has inferred so far.

I’ve made this mistake many times lol.

Best,

toz

On Thu, Apr 12, 2018 at 5:38 AM <beginners-requ...@haskell.org> wrote:

> Send Beginners mailing list submissions to
>         beginners@haskell.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> or, via email, send a message with subject or body 'help' to
>         beginners-requ...@haskell.org
>
> You can reach the person managing the list at
>         beginners-ow...@haskell.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Beginners digest..."
>
>
> Today's Topics:
>
>    1.  EitherT (mike h)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 12 Apr 2018 11:25:57 +0100
> From: mike h <mike_k_hough...@yahoo.co.uk>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
>         beginner-level topics related to Haskell <beginners@haskell.org>
> Subject: [Haskell-beginners] EitherT
> Message-ID: <57afc9f5-3601-4d18-b860-41352d3f2...@yahoo.co.uk>
> Content-Type: text/plain; charset=utf-8
>
> Hi,
> 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 :)
>
>
> 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)
>
>
>
> and here is the compilers view
> Phrase.hs:31:25: error:
>     • Couldn't match type ‘b’ with ‘a1’
>       ‘b’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       ‘a1’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
>     • In the expression: return $ Right (f rv)
>       In a case alternative: Right rv -> return $ Right (f rv)
>       In a stmt of a 'do' block:
>         case mv of
>           Left _ -> return mv
>           Right rv -> return $ Right (f rv)
>     • Relevant bindings include
>         rv :: a1 (bound at Phrase.hs:31:19)
>         mv :: Either a a1 (bound at Phrase.hs:28:9)
>         m :: EitherT m a a1 (bound at Phrase.hs:27:12)
>         f :: a1 -> b (bound at Phrase.hs:27:10)
>         fmap :: (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>           (bound at Phrase.hs:27:5)
>
>
> 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
>
> these lines from the compiler are particularly confusing
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
>
> as I believe f is    f:: a1->b
>
> So just hints please and I expect I’ll have another duh moment.
>
> Thanks
>
> Mike
>
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> ------------------------------
>
> End of Beginners Digest, Vol 118, Issue 6
> *****************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180412/e78207cb/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 12 Apr 2018 21:32:05 +0100
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] EitherT
Message-ID: <7edd529b-500b-4138-a4fd-fbdd14d5d...@yahoo.co.uk>
Content-Type: text/plain; charset="utf-8"

instance Monad m => Functor (EitherT m a) where
   fmap f m = EitherT $ do
       mv <- runEitherT m
       case mv of
           Left  lv -> return $ Left lv
           Right rv -> return $ Right (f rv)


Thanks all :) I think its correct. The compiler does! 
Mike


> On 12 Apr 2018, at 17:27, David McBride <toa...@gmail.com> wrote:
> 
> You will feel like this was obvious in hindsight.
> 
> fmap :: (a -> b) -> f a -> f b
> fmap (a -> b) -> EitherT m c a -> EitherT m c b
> 
> Now follow the types in your code.
> m :: EitherT m c a
> mv :: Either c a
> return mv :: EitherT m c a -- <- you are back to the wrong type.
> 
> How can you instead return EitherT m c b?
> 
> 
> On Thu, Apr 12, 2018 at 6:25 AM, mike h <mike_k_hough...@yahoo.co.uk 
> <mailto:mike_k_hough...@yahoo.co.uk>> wrote:
> Hi,
> 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 :)
> 
> 
> 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)
> 
> 
> 
> and here is the compilers view
> Phrase.hs:31:25: error:
>     • Couldn't match type ‘b’ with ‘a1’
>       ‘b’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       ‘a1’ is a rigid type variable bound by
>         the type signature for:
>           fmap :: forall a1 b. (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>         at Phrase.hs:27:5-8
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
>     • In the expression: return $ Right (f rv)
>       In a case alternative: Right rv -> return $ Right (f rv)
>       In a stmt of a 'do' block:
>         case mv of
>           Left _ -> return mv
>           Right rv -> return $ Right (f rv)
>     • Relevant bindings include
>         rv :: a1 (bound at Phrase.hs:31:19)
>         mv :: Either a a1 (bound at Phrase.hs:28:9)
>         m :: EitherT m a a1 (bound at Phrase.hs:27:12)
>         f :: a1 -> b (bound at Phrase.hs:27:10)
>         fmap :: (a1 -> b) -> EitherT m a a1 -> EitherT m a b
>           (bound at Phrase.hs:27:5)
> 
> 
> 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
> 
> these lines from the compiler are particularly confusing
>       Expected type: m (Either a a1)
>         Actual type: m (Either a b)
> 
> as I believe f is    f:: a1->b
> 
> So just hints please and I expect I’ll have another duh moment.
> 
> Thanks
> 
> Mike
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org <mailto:Beginners@haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners 
> <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180412/6d8f6b7d/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 118, Issue 7
*****************************************

Reply via email to