Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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.  Question about precedence (Marc Gorenstein)
   2. Re:  Question about precedence (Brandon Allbery)
   3. Re:  Question about precedence (Darren Grant)
   4. Re:  Question about precedence (Michael Orlitzky)
   5.  Still confused (Marc Gorenstein)
   6. Re:  Still confused (Ryan Bell)
   7. Re:  Still confused (Brandon Allbery)
   8. Re:  Still confused (Michael Peternell)


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

Message: 1
Date: Mon, 1 Jul 2013 12:14:04 -0400
From: Marc Gorenstein <[email protected]>
Subject: [Haskell-beginners] Question about precedence
To: [email protected]
Message-ID:
        <camqvbq5bc8vbd743qnyrpbz0+khmythakvotpvxt3cffi5a...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

What sort of beast is ( / 8) in Haskell? It looks like it is a function
that divides a number by 8.

*Main> ( / 8 ) 4
0.5

*Main> let a = ( / 8 )
*Main> a 4
0.5

-- Yup that works.

Does ( / 8 )  turn into a function that takes an argument, so that the
"left" input to the /, becomes a right input to the function?
What  precedence rule  is being followed here?

Thanks,

Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130701/8e4e70bc/attachment-0001.htm>

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

Message: 2
Date: Mon, 1 Jul 2013 12:32:07 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Question about precedence
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cakfcl4u_p6grdazvdtqpk5dsamfav6nx_5hkdor8pbneefh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Mon, Jul 1, 2013 at 12:14 PM, Marc Gorenstein
<[email protected]>wrote:

> What sort of beast is ( / 8) in Haskell? It looks like it is a function
> that divides a number by 8.
>

It's an operator section.
http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-300003.5describes
their syntax and their precedence behavior.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130701/36a6b274/attachment-0001.htm>

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

Message: 3
Date: Mon, 1 Jul 2013 09:34:01 -0700
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] Question about precedence
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <ca+9vpfdy1qkxymwjc7tu5buzjxbk4w9h0k5uxk4dmvyq5+c...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I think that since infix notation always takes two parameters, the compiler
handles parameter swapping to match the unfilled argument for convenience.
Not sure where this would be described in a spec though.

Cheers,
Darren



On Mon, Jul 1, 2013 at 9:14 AM, Marc Gorenstein
<[email protected]>wrote:

> What sort of beast is ( / 8) in Haskell? It looks like it is a function
> that divides a number by 8.
>
> *Main> ( / 8 ) 4
> 0.5
>
> *Main> let a = ( / 8 )
> *Main> a 4
> 0.5
>
> -- Yup that works.
>
> Does ( / 8 )  turn into a function that takes an argument, so that the
> "left" input to the /, becomes a right input to the function?
> What  precedence rule  is being followed here?
>
> Thanks,
>
> Marc
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130701/f38e66e7/attachment-0001.htm>

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

Message: 4
Date: Mon, 01 Jul 2013 12:44:15 -0400
From: Michael Orlitzky <[email protected]>
Subject: Re: [Haskell-beginners] Question about precedence
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 07/01/2013 12:14 PM, Marc Gorenstein wrote:
> What sort of beast is ( / 8) in Haskell? It looks like it is a function
> that divides a number by 8.
> 

Yep. This is probably easier to think about with addition rather than
division.

So, (+) is a function. It takes two arguments, and adds them. You need
the parenthesis to prevent it from being an infix operator (used in
*between* the numbers), but that's just a detail. Try it in ghci:

  ghci> (+) 1 2
  3

Thanks to currying, you can construct a function called "plus_one" by
leaving off the last argument:

  ghci> let plus_one = (+) 1
  ghci> let plus_one = (+ 1)

Either notation will work, but they do subtly different things: in the
first case, you get 1 + x, and in the second, you get x + 1. Nevertheless.

  ghci> plus_one 2
  3

Division works the same way.




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

Message: 5
Date: Mon, 1 Jul 2013 18:03:06 +0000 (UTC)
From: Marc Gorenstein <[email protected]>
Subject: [Haskell-beginners] Still confused
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi Brandon, Darren, and Michael,

Thanks for you responses, but I'm still confused. 

Here are two examples of operator sections. The first takes the infix operator 
/ and turns it into a prefix operator. 

Prelude> let eight_div_by = ((/) 8 )
Prelude> eight_div_by 4
2.0

I get that. But look at the following:  We now have a prefix operator with 
the input on the "wrong" side. 

Prelude> let div_by_eight = ( / 8 )
Prelude> div_by_eight 4
0.5

Why should ( / 8) 4 = 0.5?


Thanks again,

Marc




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

Message: 6
Date: Mon, 1 Jul 2013 14:19:10 -0400
From: Ryan Bell <[email protected]>
Subject: Re: [Haskell-beginners] Still confused
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cacad8sr6ex1kwun1bga-odexdcqtiwzbfahajs21ew2udea...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Does it help to think of it like algebra?

let x = 4
where x / 8


On Mon, Jul 1, 2013 at 2:03 PM, Marc Gorenstein
<[email protected]>wrote:

> Hi Brandon, Darren, and Michael,
>
> Thanks for you responses, but I'm still confused.
>
> Here are two examples of operator sections. The first takes the infix
> operator
> / and turns it into a prefix operator.
>
> Prelude> let eight_div_by = ((/) 8 )
> Prelude> eight_div_by 4
> 2.0
>
> I get that. But look at the following:  We now have a prefix operator with
> the input on the "wrong" side.
>
> Prelude> let div_by_eight = ( / 8 )
> Prelude> div_by_eight 4
> 0.5
>
> Why should ( / 8) 4 = 0.5?
>
>
> Thanks again,
>
> Marc
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130701/8851d069/attachment-0001.htm>

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

Message: 7
Date: Mon, 1 Jul 2013 14:20:19 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Still confused
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cakfcl4u_rgs4-tbmjwxf5yfqgqair7kbdzothaje_9nj1bs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Mon, Jul 1, 2013 at 2:03 PM, Marc Gorenstein
<[email protected]>wrote:

> Here are two examples of operator sections. The first takes the infix
> operator
> / and turns it into a prefix operator.
>
> Prelude> let eight_div_by = ((/) 8 )
> Prelude> eight_div_by 4
> 2.0
>

Yes. A section is just this conversion of an infix operator to a prefix
function, but with one parameter carried along with it. You can supply it
on either side as appropriate; (/ 8) is the same as (\x -> x / 8) which in
turn is the same as (\x -> (/) x 8), whereas (8 /) is (\x -> 8 / x) is (\x
-> (/) 8 x). Note that it must be *inside* the parentheses to be a section;
if it's outside, then it's a normal function (not operator!) parameter.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130701/578dc492/attachment-0001.htm>

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

Message: 8
Date: Mon, 1 Jul 2013 20:23:43 +0200
From: Michael Peternell <[email protected]>
Subject: Re: [Haskell-beginners] Still confused
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

(/ 8)
is the same as
(\x -> x / 8)

you can think of it as
(HERE_IS_SOMETHING_MISSING / 8)

whereas
(/) 8
is normal function currying, i.e. it is the same as
(\x -> (/) 8 x)
or
(\x -> 8 / x)

just like
foo y
is the same as
(\x -> foo y x)
if foo is a function that takes 2 parameters.

on the other hand
(8 /)
is like
(8 / HERE_IS_SOMETHING_MISSING)
which translates to
(\x -> 8 / x)

Am 01.07.2013 um 20:03 schrieb Marc Gorenstein <[email protected]>:

> Hi Brandon, Darren, and Michael,
> 
> Thanks for you responses, but I'm still confused. 
> 
> Here are two examples of operator sections. The first takes the infix 
> operator 
> / and turns it into a prefix operator. 
> 
> Prelude> let eight_div_by = ((/) 8 )
> Prelude> eight_div_by 4
> 2.0
> 
> I get that. But look at the following:  We now have a prefix operator with 
> the input on the "wrong" side. 
> 
> Prelude> let div_by_eight = ( / 8 )
> Prelude> div_by_eight 4
> 0.5
> 
> Why should ( / 8) 4 = 0.5?
> 
> 
> Thanks again,
> 
> Marc
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 61, Issue 2
****************************************

Reply via email to