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. Is map (map f) just map f? (Galaxy Being)
2. Re: Is map (map f) just map f? (Akhra Gannon)
3. Re: Is map (map f) just map f? (Galaxy Being)
4. Re: Is map (map f) just map f? (Ut Primum)
----------------------------------------------------------------------
Message: 1
Date: Wed, 7 Apr 2021 11:47:03 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Is map (map f) just map f?
Message-ID:
<CAFAhFSUXRP_v6x=6c63fbMd+=dneng5peu-qv84-6vurxq6...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'm in Bird's *Thinking Functionally with Haskell* and the topic is natural
transformations. He says
filter p . map f = map f . filter (p . f)
and he has a proof, but one step of the proof he goes from
filter p . map f = concat . map (map f) . map (test (p . f))
to
filter p . map f = map f . concat . map (test (p . f))
which means
concat . map (map f) => map f . concat
which means
map (map f) = map f
... or I'm getting this step wrong somehow. To begin with, I'm having a
hard time comprehending map(map f), Any ideas on how this is possible?
LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210407/d5204531/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 7 Apr 2021 10:06:47 -0700
From: Akhra Gannon <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Is map (map f) just map f?
Message-ID:
<cajopsucs1bpswr1abkwh0lq0sep91ohe9n-xtb0fczqchwr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Check the types!
map :: (a -> b) -> [a] -> [b]
Therefore:
map f :: [a] -> [b]
map . map :: (a -> b) -> [[a]] -> [[b]]
map (map f) :: [[a]] -> [[b]]
And,
concat :: [[a]] -> [a]
Put it all together and you should see how that rewrite works!
On Wed, Apr 7, 2021, 9:47 AM Galaxy Being <[email protected]> wrote:
> I'm in Bird's *Thinking Functionally with Haskell* and the topic is
> natural transformations. He says
>
> filter p . map f = map f . filter (p . f)
>
> and he has a proof, but one step of the proof he goes from
>
> filter p . map f = concat . map (map f) . map (test (p . f))
>
> to
>
> filter p . map f = map f . concat . map (test (p . f))
>
> which means
>
> concat . map (map f) => map f . concat
>
> which means
>
> map (map f) = map f
>
> ... or I'm getting this step wrong somehow. To begin with, I'm having a
> hard time comprehending map(map f), Any ideas on how this is possible?
>
> LB
>
>
>
>
> _______________________________________________
> 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/20210407/e4a483ee/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 8 Apr 2021 00:03:32 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Is map (map f) just map f?
Message-ID:
<cafahfsw_h7jw-+zecm4vkzehsh_u8rp2cbkb7v4sppyezhs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
So basically I can see that the type definitions would seem to deliver the
same thing. I test it
> (concat . (map (map (*5)))) [[1],[2],[3]]
[5,10,15]
> (map (*5) . concat) [[1],[2],[3]]
[5,10,15]
and can also conclude they give the same answer. So is this an example of
referential transparency, i.e., the ability to substitute code and be
assured both forms/expressions deliver the same answer?
On Wed, Apr 7, 2021 at 12:07 PM Akhra Gannon <[email protected]> wrote:
> Check the types!
>
> map :: (a -> b) -> [a] -> [b]
>
> Therefore:
>
> map f :: [a] -> [b]
>
> map . map :: (a -> b) -> [[a]] -> [[b]]
>
> map (map f) :: [[a]] -> [[b]]
>
> And,
>
> concat :: [[a]] -> [a]
>
> Put it all together and you should see how that rewrite works!
>
>
> On Wed, Apr 7, 2021, 9:47 AM Galaxy Being <[email protected]> wrote:
>
>> I'm in Bird's *Thinking Functionally with Haskell* and the topic is
>> natural transformations. He says
>>
>> filter p . map f = map f . filter (p . f)
>>
>> and he has a proof, but one step of the proof he goes from
>>
>> filter p . map f = concat . map (map f) . map (test (p . f))
>>
>> to
>>
>> filter p . map f = map f . concat . map (test (p . f))
>>
>> which means
>>
>> concat . map (map f) => map f . concat
>>
>> which means
>>
>> map (map f) = map f
>>
>> ... or I'm getting this step wrong somehow. To begin with, I'm having a
>> hard time comprehending map(map f), Any ideas on how this is possible?
>>
>> LB
>>
>>
>>
>>
>> _______________________________________________
>> 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/20210408/e6c57fde/attachment-0001.html>
------------------------------
Message: 4
Date: Thu, 8 Apr 2021 07:55:29 +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] Is map (map f) just map f?
Message-ID:
<canjdmkjrolzq5ady4ntca_-0orq-srcvenhni9rlt0hjt2v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Yes, thanks to referential transparency you can substitute
concat . map (map f)
with
map f . concat
in an expression and be sure you'll always get the same result
Il gio 8 apr 2021, 07:04 Galaxy Being <[email protected]> ha scritto:
> So basically I can see that the type definitions would seem to deliver the
> same thing. I test it
>
> > (concat . (map (map (*5)))) [[1],[2],[3]]
> [5,10,15]
> > (map (*5) . concat) [[1],[2],[3]]
> [5,10,15]
>
> and can also conclude they give the same answer. So is this an example of
> referential transparency, i.e., the ability to substitute code and be
> assured both forms/expressions deliver the same answer?
>
>
> On Wed, Apr 7, 2021 at 12:07 PM Akhra Gannon <[email protected]> wrote:
>
>> Check the types!
>>
>> map :: (a -> b) -> [a] -> [b]
>>
>> Therefore:
>>
>> map f :: [a] -> [b]
>>
>> map . map :: (a -> b) -> [[a]] -> [[b]]
>>
>> map (map f) :: [[a]] -> [[b]]
>>
>> And,
>>
>> concat :: [[a]] -> [a]
>>
>> Put it all together and you should see how that rewrite works!
>>
>>
>> On Wed, Apr 7, 2021, 9:47 AM Galaxy Being <[email protected]> wrote:
>>
>>> I'm in Bird's *Thinking Functionally with Haskell* and the topic is
>>> natural transformations. He says
>>>
>>> filter p . map f = map f . filter (p . f)
>>>
>>> and he has a proof, but one step of the proof he goes from
>>>
>>> filter p . map f = concat . map (map f) . map (test (p . f))
>>>
>>> to
>>>
>>> filter p . map f = map f . concat . map (test (p . f))
>>>
>>> which means
>>>
>>> concat . map (map f) => map f . concat
>>>
>>> which means
>>>
>>> map (map f) = map f
>>>
>>> ... or I'm getting this step wrong somehow. To begin with, I'm having a
>>> hard time comprehending map(map f), Any ideas on how this is possible?
>>>
>>> LB
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
>>
> _______________________________________________
> 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/20210408/2be2759d/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 153, Issue 2
*****************************************