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. understanding function signature alignement
([email protected])
2. Re: understanding function signature alignement (Tony Morris)
3. Re: understanding function signature alignement (sasa bogicevic)
----------------------------------------------------------------------
Message: 1
Date: Thu, 9 Aug 2018 10:32:57 +0200
From: "[email protected]" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] understanding function signature
alignement
Message-ID:
<CAJqT=y+xqgn2rzjbftt0y+6spj+hwxrcspafczpvfzejidi...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello,
I'm going through Haskellbook and while doing some exercises I'm stack with
trying to explain myself how types matches in this examples:
meh :: Monad m => [a] -> (a -> m b) -> m [b]
meh [] _ = pure []
meh (x:xs) f = (:) <$> f x <*> meh xs f
flipType :: (Monad m) => [m a] -> m [a]
flipType xs = meh xs id
What puzzles me is how id function which is of type (a->a) can fit here
where meh function is requesting function of type (a->m b)?
The function (a -> m b) is function that says give me anything and I will
give back anything wrapped up into some monad structure; id ( a -> a) on
other hand says give me anything and I will return it back to you. So, to
me, the first function is somehow more restricted than id function because
it puts limitation on what output of that function can be and I'm
struggling to understand how id function can fit here.
I hope someone can help me how to reason about these functions here?
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180809/c5f0b6a2/attachment-0001.html>
------------------------------
Message: 2
Date: Thu, 9 Aug 2018 18:36:50 +1000
From: Tony Morris <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] understanding function signature
alignement
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
The (a) and (b) are different in each case. Let's rewrite it and rename
the variables to emphasise the difference.
meh :: Monad m => [a] -> (a -> m b) -> m [b]
flipType :: (Monad k) => [k x] -> k [x]
id :: q -> q
This means that id can accept any argument type, as long as it returns
the same argument type. For example:
id :: m b -> m b
When it is used like that, then (a) turns into (m b).
Similarly, meh can have this type:
meh :: Monad m => [m b] -> (m b -> m b) -> m [b]
All I did was specialise the (a) type-variable, which can be anything,
as long as they all change. Now it is clear that when I put id into the
second argument position, I get the type [m b] -> m [b]
On 09/08/18 18:32, [email protected] wrote:
> Hello,
>
> I'm going through Haskellbook and while doing some exercises I'm stack
> with trying to explain myself how types matches in this examples:
>
> meh :: Monad m => [a] -> (a -> m b) -> m [b]
> meh [] _ = pure []
> meh (x:xs) f = (:) <$> f x <*> meh xs f
>
>
> flipType :: (Monad m) => [m a] -> m [a]
> flipType xs = meh xs id
>
> What puzzles me is how id function which is of type (a->a) can fit
> here where meh function is requesting function of type (a->m b)?
>
> The function (a -> m b) is function that says give me anything and I
> will give back anything wrapped up into some monad structure; id ( a
> -> a) on other hand says give me anything and I will return it back to
> you. So, to me, the first function is somehow more restricted than id
> function because it puts limitation on what output of that function
> can be and I'm struggling to understand how id function can fit here.
>
> I hope someone can help me how to reason about these functions here?
>
> thanks
>
>
>
>
> _______________________________________________
> 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/20180809/9a54af95/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180809/9a54af95/attachment-0001.sig>
------------------------------
Message: 3
Date: Thu, 9 Aug 2018 10:47:50 +0200
From: sasa bogicevic <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] understanding function signature
alignement
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
You can also put another function as the argument to the id :
ghci > x :: a -> m b;x = undefined
ghci > :t (id x)
(id x) :: a -> m b
> On 9 Aug 2018, at 10:36, Tony Morris <[email protected]> wrote:
>
> The (a) and (b) are different in each case. Let's rewrite it and rename the
> variables to emphasise the difference.
>
> meh :: Monad m => [a] -> (a -> m b) -> m [b]
>
> flipType :: (Monad k) => [k x] -> k [x]
>
> id :: q -> q
>
> This means that id can accept any argument type, as long as it returns the
> same argument type. For example:
>
> id :: m b -> m b
>
> When it is used like that, then (a) turns into (m b).
>
> Similarly, meh can have this type:
>
> meh :: Monad m => [m b] -> (m b -> m b) -> m [b]
>
> All I did was specialise the (a) type-variable, which can be anything, as
> long as they all change. Now it is clear that when I put id into the second
> argument position, I get the type [m b] -> m [b]
>
>
> On 09/08/18 18:32, [email protected] <mailto:[email protected]> wrote:
>> Hello,
>>
>> I'm going through Haskellbook and while doing some exercises I'm stack with
>> trying to explain myself how types matches in this examples:
>>
>> meh :: Monad m => [a] -> (a -> m b) -> m [b]
>> meh [] _ = pure []
>> meh (x:xs) f = (:) <$> f x <*> meh xs f
>>
>>
>> flipType :: (Monad m) => [m a] -> m [a]
>> flipType xs = meh xs id
>>
>> What puzzles me is how id function which is of type (a->a) can fit here
>> where meh function is requesting function of type (a->m b)?
>>
>> The function (a -> m b) is function that says give me anything and I will
>> give back anything wrapped up into some monad structure; id ( a -> a) on
>> other hand says give me anything and I will return it back to you. So, to
>> me, the first function is somehow more restricted than id function because
>> it puts limitation on what output of that function can be and I'm struggling
>> to understand how id function can fit here.
>>
>> I hope someone can help me how to reason about these functions here?
>>
>> thanks
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected] <mailto:[email protected]>
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> <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/20180809/aaa994fc/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 122, Issue 1
*****************************************