[Haskell-beginners] $ versus .

Kim-Ee Yeoh ky3 at atamo.com
Tue Jan 26 01:58:11 UTC 2021


init $ tail [1,2,3]
= init (tail ([1,2,3])) -- a la Lisp

Now, functional programming is awesomest at abstractions. What if we could
abstract out "init (tail"?

Then we could write

chopEnds = init (tail

But that looks weird. It's only got the left half of a parens pair!

Does that explain why you should not expect the same result?

A separate question is why the compiler even type-checks "init $ tail" in
the first place. What do you think is going on there?

On Tue, Jan 26, 2021 at 1:16 AM Lawrence Bottorff <borgauf at gmail.com> wrote:

> I've got this
>
> > init $ tail [1,2,3]
> [2]
>
> and this
>
> > chopEnds = init $ tail
> > chopEnds [1,2,3]
> [1,2]
>
> What happened? Why is it not just init $ tail [1,2,3] ?
>
> This works fine
>
> > chopEnds2 = init . tail
> > chopEnds2 [1,2,3]
> [2]
>
> What am I missing?
>
> LB
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-- 
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210126/a8da4628/attachment.html>


More information about the Beginners mailing list