[Haskell-beginners] $ versus .

Bob Ippolito bob at redivi.com
Mon Jan 25 19:18:20 UTC 2021


I think what you're missing is what you actually typed in the first case.

This is a type error, it will not compile or run:

chopEnds = init $ tail

The $ operator can always be rewritten as parentheses, in this case:

chopEnds = init (tail)

Which has the same incorrectly typed meaning as:

chopEnds = init tail

The "result" you pasted looks equivalent to:

chopEnds = init

Perhaps this is what you typed? In this case the argument tail it will
shadow the existing binding of the Prelude tail, which would be confusing
so with -Wall it would issue a compiler warning:

chopEnds tail = init $ tail

<interactive>:2:10: warning: [-Wname-shadowing]
    This binding for ‘tail’ shadows the existing binding
      imported from ‘Prelude’ (and originally defined in ‘GHC.List’)


On Mon, Jan 25, 2021 at 10: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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210125/6c9d04f8/attachment.html>


More information about the Beginners mailing list