<div dir="auto">The difference is that one of them is:</div><div dir="auto"><br></div><div dir="auto">— unnecessary parentheses for emphasis</div><div dir="auto">(init tail) [1, 2, 3]</div><div dir="auto"><br></div><div dir="auto">And the other is</div><div dir="auto"><br></div><div dir="auto">— parentheses required for correct evaluation</div><div dir="auto">init (tail [1, 2, 3])</div><div dir="auto"><br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 26, 2021 at 08:23 Lawrence Bottorff <<a href="mailto:borgauf@gmail.com">borgauf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">> :t (init tail)<br>: error:<br>: * Couldn't match expected type `[a]'<br>: with actual type `[a0] -> [a0]'<br>: * Probable cause: `tail' is applied to too few arguments<br>: In the first argument of `init', namely `tail'<br>: In the expression: (init tail)<br><div><br></div><div>> :t (init . tail)<br>: (init . tail) :: [a] -> [a]<br></div><div><br></div><div>> :t init $ tail</div>: error:<br> * Couldn't match expected type `[a]'<br> with actual type `[a0] -> [a0]'<br> * Probable cause: `tail' is applied to too few arguments<br> In the second argument of `($)', namely `tail'<br> In the expression: init $ tail<div><br></div><div>> chopEnds = init $ tail</div><div>> chopEnds [1,2,3]</div><div>error: ...<br> * Variable not in scope: chopEnds1 :: [Integer] -> t<br></div><div>...</div><div><br></div><div>but then<br></div><div><div><br></div><div>> init $ tail [1,2,3]<br>[2]<br><div><br></div></div></div><div>Not sure what I'm missing here. It doesn't make sense to me that the last expression works, but no version of a closure </div><div><br></div><div>chopEnds = init $ tail<br></div><div><br></div><div>does.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 25, 2021 at 7:58 PM Kim-Ee Yeoh <<a href="mailto:ky3@atamo.com" target="_blank">ky3@atamo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">init $ tail [1,2,3]</div><div dir="auto">= init (tail ([1,2,3])) -- a la Lisp</div><div dir="auto"><br></div><div dir="auto">Now, functional programming is awesomest at abstractions. What if we could abstract out "init (tail"? </div><div dir="auto"><br></div><div dir="auto">Then we could write </div><div dir="auto"><br></div><div dir="auto">chopEnds = init (tail</div><div dir="auto"><br></div><div dir="auto">But that looks weird. It's only got the left half of a parens pair!</div><div dir="auto"><br></div><div dir="auto">Does that explain why you should not expect the same result?</div><div dir="auto"><br></div><div dir="auto">A separate question is why the compiler even type-checks "init $ tail" in the first place. What do you think is going on there?</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff <<a href="mailto:borgauf@gmail.com" target="_blank">borgauf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I've got this<div><br></div><div>> init $ tail [1,2,3]<br></div><div>[2]<br></div><div><br></div><div>and this</div><div><br></div><div>> chopEnds = init $ tail<br></div><div>> chopEnds [1,2,3]</div><div>[1,2]<br></div><div><br></div><div>What happened? Why is it not just init $ tail [1,2,3] ?</div><div><br></div><div>This works fine </div><div><br></div><div>> chopEnds2 = init . tail</div><div>> chopEnds2 [1,2,3]</div><div>[2]<br></div><div><br></div><div>What am I missing?</div><div><br></div><div>LB</div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div>-- <br><div dir="ltr">-- Kim-Ee</div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div>