<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You can also put another function as the argument to the id :<div class=""><br class=""></div><div class=""><div class="">ghci > x :: a -> m b;x = undefined</div><div class="">ghci > :t (id x)</div><div class="">(id x) :: a -> m b</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 9 Aug 2018, at 10:36, Tony Morris <<a href="mailto:tonymorris@gmail.com" class="">tonymorris@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
<div text="#000000" bgcolor="#FFFFFF" class=""><p class="">The (a) and (b) are different in each case. Let's rewrite it and
rename the variables to emphasise the difference.<br class="">
<br class="">
meh :: Monad m => [a] -> (a -> m b) -> m [b]<br class="">
</p><p class="">flipType :: (Monad k) => [k x] -> k [x]<br class="">
<br class="">
id :: q -> q</p><p class="">This means that id can accept any argument type, as long as it
returns the same argument type. For example:<br class="">
<br class="">
id :: m b -> m b<br class="">
<br class="">
When it is used like that, then (a) turns into (m b).<br class="">
<br class="">
Similarly, meh can have this type:<br class="">
<br class="">
meh :: Monad m => [m b] -> (m b -> m b) -> m [b]<br class="">
<br class="">
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]<br class="">
</p>
<br class="">
<div class="moz-cite-prefix">On 09/08/18 18:32, <a class="moz-txt-link-abbreviated" href="mailto:simkestuff@gmail.com">simkestuff@gmail.com</a>
wrote:<br class="">
</div>
<blockquote type="cite" cite="mid:CAJqT=Y+xQgn2rzJBftt0y+6sPJ+HwXRCSPAFczpVFZeJiDimvg@mail.gmail.com" class="">
<meta http-equiv="content-type" content="text/html; charset=utf-8" class="">
<div dir="ltr" class="">Hello,
<div class=""><br class="">
</div>
<div class="">I'm going through Haskellbook and while doing some
exercises I'm stack with trying to explain myself how types
matches in this examples:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">meh :: Monad m => [a] -> (a -> m b) -> m [b]</div>
<div class="">meh [] _ = pure []</div>
<div class="">meh (x:xs) f = (:) <$> f x <*> meh xs f</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">flipType :: (Monad m) => [m a] -> m [a]</div>
<div class="">flipType xs = meh xs id</div>
</div>
<div class=""><br class="">
</div>
<div class="">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)?</div>
<div class=""><br class="">
</div>
<div class="">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.</div>
<div class=""><br class="">
</div>
<div class="">I hope someone can help me how to reason about these
functions here?</div>
<div class=""><br class="">
</div>
<div class="">thanks</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
<br class="">
<fieldset class="mimeAttachmentHeader"></fieldset>
<br class="">
<pre wrap="" class="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br class="">
</div>
_______________________________________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br class=""></div></blockquote></div><br class=""></div></div></body></html>