Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  $ versus . (Lawrence Bottorff)
   2. Re:  $ versus . (Bob Ippolito)
   3. Re:  $ versus . (Kim-Ee Yeoh)


----------------------------------------------------------------------

Message: 1
Date: Mon, 25 Jan 2021 12:16:05 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] $ versus .
Message-ID:
        <cafahfsud_yhwd4w_4xjeskubkxt32bxxr5c6kfu+o2vcqhm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210125/885f5850/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 25 Jan 2021 11:18:20 -0800
From: Bob Ippolito <b...@redivi.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:
        <cacwmpm9h+ycaax6kpzioqgu8wuam-e9hyno47xwgwok1m3v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <borg...@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@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-0001.html>

------------------------------

Message: 3
Date: Tue, 26 Jan 2021 08:58:11 +0700
From: Kim-Ee Yeoh <k...@atamo.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] $ versus .
Message-ID:
        <CAPY+ZdS6WqRLjrZMe4NhP7jAWQOWtsG-AZy3=_4xhz6f5l3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <borg...@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@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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 150, Issue 13
******************************************

Reply via email to