Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. fmap composition (Marco Turchetto)
2. Re: fmap composition (Ut Primum)
3. Re: fmap composition (Marco Turchetto)
----------------------------------------------------------------------
Message: 1
Date: Tue, 12 Jun 2018 18:12:05 +0200
From: Marco Turchetto <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] fmap composition
Message-ID:
<caaf93tjtwgy7dsv-zkmag+kz5z4u6wwwmwybjvbs4wktue6...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm reading the "Haskell programming" book and in chapter 16 about functors
they combine two "fmap" with the "(.)" function.
I really don't understand how the type of "fmap . fmap" is "(Functor f2,
Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
The thing that really freaks me out is that I thought that "(.)" arguments
are ONLY two unary function.
Maybe there is some curring magic underline, there is someone that can
explain to me how the type of "fmap . fmap" is derived from the type of
"fmap" and "(.)"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180612/77607a47/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 12 Jun 2018 19:35:30 +0200
From: Ut Primum <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] fmap composition
Message-ID:
<canjdmkl9wwsemj1zol5egfx4icuefzwzcv6ka-xrbfrdjev...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
as you probably know, fmap ha type
fmap :: Functor f => (a -> b) -> f a -> f b
So, you can see fmap as a unary funcrion that takes an argument of type
(a->b) and returns a result of type (f a -> f b).
For example, if you define
identity x = x
then
fmap identity :: Functor f => f b -> f b
(here a = b because identity :: p -> p )
Now, the type of (.) is;
(.) :: (b -> c) -> (a -> b) -> (a -> c)
if you write fmap . fmap, in general (a priori) the type of the fmaps
could be
FIRSTFMAP fmap :: Functor f1 => (d -> e) -> f1 d -> f1 e
SECONDFMAP fmap :: Functor f2 => (g -> h) -> f2 g -> f2 h
let's see if there must be some bonds between types d,e,g,h, due to the
type of (.)
(b -> c) = FIRSTFMAP (the first argument of (.) )
(a -> b) = SECONDFMAP (the second argument of (.) )
so, we have (I'll not write "Functor f1" or "Functor f2", we know f1 and f2
are functors)
b = (d -> e)
c = (f1 d -> f1 e)
a = (g -> h)
b = (f2 g -> f2 h)
now, it must be b=b, so the type (d -> e) must be the same type of (f2 g ->
f2 h)
So
d = f2 g
e = f2 h
The result of fmap . fmap, will be of type (a -> c) that is
(g -> h) -> (f1 d -> f1 e) = (g -> h) -> f1 d -> f1 e
that, remebering the conditions on d and e, is
(g -> h) -> f1 (f2 g) -> f1 (f2 h)
which is the type you found on the book
(you only need to add that f1, f2 are Functors, and the names of f and g
can of course be replaced with a and b)
Cheers,
Ut
2018-06-12 18:12 GMT+02:00 Marco Turchetto <[email protected]>:
> I'm reading the "Haskell programming" book and in chapter 16 about
> functors they combine two "fmap" with the "(.)" function.
> I really don't understand how the type of "fmap . fmap" is "(Functor f2,
> Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
>
> The thing that really freaks me out is that I thought that "(.)" arguments
> are ONLY two unary function.
> Maybe there is some curring magic underline, there is someone that can
> explain to me how the type of "fmap . fmap" is derived from the type of
> "fmap" and "(.)"?
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180612/27155ecd/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 13 Jun 2018 09:38:40 +0200
From: Marco Turchetto <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] fmap composition
Message-ID:
<CAAF93TLNr2d2vd0B5jSS=xfbkjsa7ucznkpssyph0op9ssy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
It's all clear as day.
Thanks
On Tue, 12 Jun 2018 at 19:35 Ut Primum <[email protected]> wrote:
> Hi,
> as you probably know, fmap ha type
> fmap :: Functor f => (a -> b) -> f a -> f b
> So, you can see fmap as a unary funcrion that takes an argument of type
> (a->b) and returns a result of type (f a -> f b).
>
> For example, if you define
> identity x = x
> then
> fmap identity :: Functor f => f b -> f b
> (here a = b because identity :: p -> p )
>
> Now, the type of (.) is;
> (.) :: (b -> c) -> (a -> b) -> (a -> c)
>
> if you write fmap . fmap, in general (a priori) the type of the fmaps
> could be
> FIRSTFMAP fmap :: Functor f1 => (d -> e) -> f1 d -> f1 e
> SECONDFMAP fmap :: Functor f2 => (g -> h) -> f2 g -> f2 h
>
> let's see if there must be some bonds between types d,e,g,h, due to the
> type of (.)
>
> (b -> c) = FIRSTFMAP (the first argument of (.) )
> (a -> b) = SECONDFMAP (the second argument of (.) )
>
> so, we have (I'll not write "Functor f1" or "Functor f2", we know f1 and
> f2 are functors)
>
> b = (d -> e)
> c = (f1 d -> f1 e)
> a = (g -> h)
> b = (f2 g -> f2 h)
>
> now, it must be b=b, so the type (d -> e) must be the same type of (f2 g
> -> f2 h)
> So
> d = f2 g
> e = f2 h
>
> The result of fmap . fmap, will be of type (a -> c) that is
> (g -> h) -> (f1 d -> f1 e) = (g -> h) -> f1 d -> f1 e
> that, remebering the conditions on d and e, is
> (g -> h) -> f1 (f2 g) -> f1 (f2 h)
>
> which is the type you found on the book
> (you only need to add that f1, f2 are Functors, and the names of f and g
> can of course be replaced with a and b)
>
> Cheers,
> Ut
>
> 2018-06-12 18:12 GMT+02:00 Marco Turchetto <[email protected]>:
>
>> I'm reading the "Haskell programming" book and in chapter 16 about
>> functors they combine two "fmap" with the "(.)" function.
>> I really don't understand how the type of "fmap . fmap" is "(Functor f2,
>> Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
>>
>> The thing that really freaks me out is that I thought that "(.)"
>> arguments are ONLY two unary function.
>> Maybe there is some curring magic underline, there is someone that can
>> explain to me how the type of "fmap . fmap" is derived from the type of
>> "fmap" and "(.)"?
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180613/d160adaf/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 120, Issue 7
*****************************************