Send Beginners mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1. Re:  Usage of $ (Martin Vlk)
   2. Re:  Usage of $ (Mike Meyer)


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

Message: 1
Date: Mon, 08 Jun 2015 10:01:18 +0000
From: Martin Vlk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Usage of $
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252

Mike Meyer:
> s mp $ n - 1 parses as s mp (n - 1)
> s mp n - 1 parses as (s mp n) - 1


Hi, I think it is misleading to say that $ "parses" to something.
($) is an infix operator with type:

($) :: (a -> b) -> a -> b       -- Defined in ?GHC.Base?
infixr 0 $

So what it does is it takes a function on the left hand side and applies
it to the second argument on the right hand side. The trick is it has
the lowest possible precedence value (0) so everything on the right hand
side will be evaluated before applying the function on the left.

This is useful as a convenience if you want to avoid writing too many
parentheses.

Martin


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

Message: 2
Date: Mon, 8 Jun 2015 05:20:13 -0500
From: Mike Meyer <[email protected]>
To: beginners <[email protected]>
Subject: Re: [Haskell-beginners] Usage of $
Message-ID:
        <CAD=7u2cruv4til5y7yktcszkf5zrslwdcf6js_gcomhcury...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Jun 8, 2015 05:01, "Martin Vlk" <[email protected]> wrote:
>
> Mike Meyer:
> > s mp $ n - 1 parses as s mp (n - 1)
> > s mp n - 1 parses as (s mp n) - 1
>
>
> Hi, I think it is misleading to say that $ "parses" to something.

Which is why I didn't say such a thing. The two sentences show how the
expressions he was having trouble with are parsed.

> ($) is an infix operator with type:
>
> ($) :: (a -> b) -> a -> b       -- Defined in ?GHC.Base?
> infixr 0 $
>
> So what it does is it takes a function on the left hand side and applies
> it to the second argument on the right hand side. The trick is it has
> the lowest possible precedence value (0) so everything on the right hand
> side will be evaluated before applying the function on the left.

Which explains why the expression containing a $ parses as it does, which
is also useful information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150608/8a70207c/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 84, Issue 11
*****************************************

Reply via email to