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. Re: map type explanation (Lawrence Bottorff)
2. Re: map type explanation (Bruno Barbier)
3. Re: map type explanation (Lawrence Bottorff)
----------------------------------------------------------------------
Message: 1
Date: Fri, 18 Dec 2020 16:55:30 -0600
From: Lawrence Bottorff <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] map type explanation
Message-ID:
<cafahfsw_kaqig3irqufp77j3wqsgwbmqujfszqyjoqcjbwh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Why is it not just
a -> b -> [a] -> [b]
again, why the parentheses?
On Fri, Dec 18, 2020 at 4:10 PM Ut Primum <[email protected]> wrote:
> Hi,
>
> a -> b is the type of a function taking arguments of a generic type (we
> call it a) and returning results of another type, that we call b.
>
> So
> (a -> b ) -> [a] -> [b]
> Means that you have a first argument that is a function (a-> b), a second
> argument that is a list of elements of the same type of the function input,
> and that the returned element is a list of things of the type of the output
> of the function.
>
> Cheers,
> Ut
>
> Il ven 18 dic 2020, 23:02 Lawrence Bottorff <[email protected]> ha
> scritto:
>
>> Thank you, but why in
>>
>> map :: (a -> b) -> [a] -> [b]
>>
>> are there parentheses around a -> b ? In general, what is the currying
>> aspect of this?
>>
>>
>> On Fri, Dec 18, 2020 at 12:43 PM David McBride <[email protected]> wrote:
>>
>>> They are not parameters, they are the types of the parameters.
>>>
>>> In this case a can really be anything, Int, Char, whatever, so long as
>>> the function takes a single argument of that type and the list that is
>>> given has elements of that same type.
>>> It is the same for b, it doesn't matter what b ends up being, so long as
>>> when you call that function the function's return value is compatible with
>>> the element type of the list that you intended to return from the entire
>>> statement.
>>>
>>> You can mess with it yourself in ghci to see how type inference works.
>>>
>>> >:t show
>>> :show :: Show a => a -> String
>>> >:t map show
>>> map show :: Show a => [a] -> [String]
>>> > :t flip map [1::Int]
>>> > flip map [1::Int] :: (Int -> b) -> [b]
>>>
>>>
>>> On Fri, Dec 18, 2020 at 1:31 PM Lawrence Bottorff <[email protected]>
>>> wrote:
>>>
>>>> I'm looking at this
>>>>
>>>> ghci> :type map
>>>> map :: (a -> b) -> [a] -> [b]
>>>>
>>>> and wondering what the (a -> b) part is about. map takes a function
>>>> and applies it to an incoming list. Good. Understood. I'm guessing that the
>>>> whole Haskell type declaration idea is based on currying, and I do
>>>> understand how the (a -> b) part "takes" an incoming list, [a] and
>>>> produces the [b] output. Also, I don't understand a and b very well
>>>> either. Typically, a is just a generic variable, then b is another
>>>> generic variable not necessarily the same as a. But how are they being
>>>> used in this type declaration?
>>>>
>>>> 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
>>
> _______________________________________________
> 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/20201218/323026a9/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 19 Dec 2020 00:19:41 +0100
From: Bruno Barbier <[email protected]>
To: Lawrence Bottorff <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] map type explanation
Message-ID: <[email protected]>
Content-Type: text/plain
Hi Lawrence,
Lawrence Bottorff <[email protected]> writes:
> Why is it not just
>
> a -> b -> [a] -> [b]
>
> again, why the parentheses?
In Haskell, (->) is a binary operator and is right associative. If you write:
a -> b -> [a] -> [b]
it implicitly means:
a -> (b -> ([a] -> [b]))
So here, you need explicit parenthesis:
(a -> b) -> [a] -> [b]
to mean:
(a -> b) -> ([a] -> [b])
It's more about parsing binary operators than about types.
Does it help ?
Bruno
> On Fri, Dec 18, 2020 at 4:10 PM Ut Primum <[email protected]> wrote:
>
>> Hi,
>>
>> a -> b is the type of a function taking arguments of a generic type (we
>> call it a) and returning results of another type, that we call b.
>>
>> So
>> (a -> b ) -> [a] -> [b]
>> Means that you have a first argument that is a function (a-> b), a second
>> argument that is a list of elements of the same type of the function input,
>> and that the returned element is a list of things of the type of the output
>> of the function.
>>
>> Cheers,
>> Ut
>>
>> Il ven 18 dic 2020, 23:02 Lawrence Bottorff <[email protected]> ha
>> scritto:
>>
>>> Thank you, but why in
>>>
>>> map :: (a -> b) -> [a] -> [b]
>>>
>>> are there parentheses around a -> b ? In general, what is the currying
>>> aspect of this?
>>>
>>>
>>> On Fri, Dec 18, 2020 at 12:43 PM David McBride <[email protected]> wrote:
>>>
>>>> They are not parameters, they are the types of the parameters.
>>>>
>>>> In this case a can really be anything, Int, Char, whatever, so long as
>>>> the function takes a single argument of that type and the list that is
>>>> given has elements of that same type.
>>>> It is the same for b, it doesn't matter what b ends up being, so long as
>>>> when you call that function the function's return value is compatible with
>>>> the element type of the list that you intended to return from the entire
>>>> statement.
>>>>
>>>> You can mess with it yourself in ghci to see how type inference works.
>>>>
>>>> >:t show
>>>> :show :: Show a => a -> String
>>>> >:t map show
>>>> map show :: Show a => [a] -> [String]
>>>> > :t flip map [1::Int]
>>>> > flip map [1::Int] :: (Int -> b) -> [b]
>>>>
>>>>
>>>> On Fri, Dec 18, 2020 at 1:31 PM Lawrence Bottorff <[email protected]>
>>>> wrote:
>>>>
>>>>> I'm looking at this
>>>>>
>>>>> ghci> :type map
>>>>> map :: (a -> b) -> [a] -> [b]
>>>>>
>>>>> and wondering what the (a -> b) part is about. map takes a function
>>>>> and applies it to an incoming list. Good. Understood. I'm guessing that
>>>>> the
>>>>> whole Haskell type declaration idea is based on currying, and I do
>>>>> understand how the (a -> b) part "takes" an incoming list, [a] and
>>>>> produces the [b] output. Also, I don't understand a and b very well
>>>>> either. Typically, a is just a generic variable, then b is another
>>>>> generic variable not necessarily the same as a. But how are they being
>>>>> used in this type declaration?
>>>>>
>>>>> 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
>>>
>> _______________________________________________
>> 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
------------------------------
Message: 3
Date: Fri, 18 Dec 2020 21:36:22 -0600
From: Lawrence Bottorff <[email protected]>
To: Bruno Barbier <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] map type explanation
Message-ID:
<CAFAhFSXZ-sTzoAy+zJkGOweOMPaubS7gP0Jr9gZru8SU7=j...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
So in effect
a -> b -> [a] -> [b]
wants to be, would be
a -> (b -> ([a] -> [b]))
without the parens (which is a natural result of lambda calculus, perhaps?)
-- which is not what is meant by map. But underlying a Haskell type
declaration is currying, is it not? At the type declaration level, it's all
currying, correct?
Conceptually, I understand how the a -> b "event" needs to be a "package"
to apply to the list [a]. The map function commandeers the target function
(which alone by itself does some a -> b evaluation) to be a new object that
is then applied to each member of list [a]. Good. So (a -> b) then is a
notation that signifies this "package-ness".
Does anyone have examples of other "packaging" where a function doing some a
-> b is changed to (a -> b) ?
On Fri, Dec 18, 2020 at 5:18 PM Bruno Barbier <[email protected]> wrote:
>
> Hi Lawrence,
>
> Lawrence Bottorff <[email protected]> writes:
>
> > Why is it not just
> >
> > a -> b -> [a] -> [b]
> >
> > again, why the parentheses?
>
> In Haskell, (->) is a binary operator and is right associative. If you
> write:
>
> a -> b -> [a] -> [b]
>
> it implicitly means:
>
> a -> (b -> ([a] -> [b]))
>
> So here, you need explicit parenthesis:
>
> (a -> b) -> [a] -> [b]
>
> to mean:
> (a -> b) -> ([a] -> [b])
>
> It's more about parsing binary operators than about types.
>
> Does it help ?
>
> Bruno
>
> > On Fri, Dec 18, 2020 at 4:10 PM Ut Primum <[email protected]> wrote:
> >
> >> Hi,
> >>
> >> a -> b is the type of a function taking arguments of a generic type (we
> >> call it a) and returning results of another type, that we call b.
> >>
> >> So
> >> (a -> b ) -> [a] -> [b]
> >> Means that you have a first argument that is a function (a-> b), a
> second
> >> argument that is a list of elements of the same type of the function
> input,
> >> and that the returned element is a list of things of the type of the
> output
> >> of the function.
> >>
> >> Cheers,
> >> Ut
> >>
> >> Il ven 18 dic 2020, 23:02 Lawrence Bottorff <[email protected]> ha
> >> scritto:
> >>
> >>> Thank you, but why in
> >>>
> >>> map :: (a -> b) -> [a] -> [b]
> >>>
> >>> are there parentheses around a -> b ? In general, what is the currying
> >>> aspect of this?
> >>>
> >>>
> >>> On Fri, Dec 18, 2020 at 12:43 PM David McBride <[email protected]>
> wrote:
> >>>
> >>>> They are not parameters, they are the types of the parameters.
> >>>>
> >>>> In this case a can really be anything, Int, Char, whatever, so long as
> >>>> the function takes a single argument of that type and the list that is
> >>>> given has elements of that same type.
> >>>> It is the same for b, it doesn't matter what b ends up being, so long
> as
> >>>> when you call that function the function's return value is compatible
> with
> >>>> the element type of the list that you intended to return from the
> entire
> >>>> statement.
> >>>>
> >>>> You can mess with it yourself in ghci to see how type inference works.
> >>>>
> >>>> >:t show
> >>>> :show :: Show a => a -> String
> >>>> >:t map show
> >>>> map show :: Show a => [a] -> [String]
> >>>> > :t flip map [1::Int]
> >>>> > flip map [1::Int] :: (Int -> b) -> [b]
> >>>>
> >>>>
> >>>> On Fri, Dec 18, 2020 at 1:31 PM Lawrence Bottorff <[email protected]>
> >>>> wrote:
> >>>>
> >>>>> I'm looking at this
> >>>>>
> >>>>> ghci> :type map
> >>>>> map :: (a -> b) -> [a] -> [b]
> >>>>>
> >>>>> and wondering what the (a -> b) part is about. map takes a function
> >>>>> and applies it to an incoming list. Good. Understood. I'm guessing
> that the
> >>>>> whole Haskell type declaration idea is based on currying, and I do
> >>>>> understand how the (a -> b) part "takes" an incoming list, [a] and
> >>>>> produces the [b] output. Also, I don't understand a and b very well
> >>>>> either. Typically, a is just a generic variable, then b is another
> >>>>> generic variable not necessarily the same as a. But how are they
> being
> >>>>> used in this type declaration?
> >>>>>
> >>>>> 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
> >>>
> >> _______________________________________________
> >> 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/20201218/cd3a240d/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 149, Issue 12
******************************************