[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell
Subject:    Re: Left hand sides and priorities.
From:       Joe Fasel <jhf () chaco ! c3 ! lanl ! gov>
Date:       1991-03-07 22:26:15
Message-ID: 9103070512.AA13870 () chaco ! c3 ! lanl ! gov ! 
[Download RAW message or body]

Original-Via: uk.ac.nsf; Thu, 7 Mar 91 20:47:44 GMT
Date: Wed, 6 Mar 91 22:12:06 MST
From: Joe Fasel <jhf@chaco.c3.lanl.gov>
To: haskell <haskell%edu.yale.cs@yalevm.ycc.yale.edu>
Subject: Re: Left hand sides and priorities.
Original-Sender: jhf <jhf%gov.lanl.c3.chaco%edu.yale.ycc.yalevm%edu.yale.cs@yale.edu>
Sender: haskell-request@cs.glasgow.ac.uk

| From: Kent Karlsson <kent@cs.chalmers.se>
|
|                         LEFT HAND SIDES and PRIORITIES
|                         ==============================
|
| On p. 32 the Haskell report says:
|
|         lhs -> ...
|              |   apat1  varop  apat2
|              | ( apat1  varop  apat2 ) apat3 ... apatk          (k >= 3)
|
| Why must the argument patterns be "apat"s?  In expressions and patterns
| the priority (and associativity) of operators is used, why not in "lhs"s?
| I.e. why not:
|
|         lhs -> ...
|              |   pat1  varop  pat2
|              | ( pat1  varop  pat2 ) apat3 ... apatk            (k >= 3)

Indeed, I stumbled over this one while doing the standard prelude.  For
example, in PreludeRatio, I wrote

	    x:%y + x':%y'   =  ((x*m) `div` y + (x'*m) `div` y') :% m
	                       where m = lcm y y'

and then found that the lhs needs to be  (x:%y) + (x':%y') .  At the time,
I think I convinced myself that the restriction wasn't so bad, since it
forces one to make very plain what operator is being bound, but on
reconsideration, I agree with Kent:  The inconsistency between parsing of
lhs and rhs is surprising.


|    Another priority issue, why is  -2^2  equal to  4  while  0-2^2  is  -4 ?
| I find this rather surprising, as would any neophyte programmer... :-)
| I think unary minus should have the *same* priority as binary minus.  From
| the point of view of the Haskell report:  change      exp  ->  - aexp
| to     exp  ->  - exp    and state that unary and binary minus have the
| same priority.  (I.e. the parenthesis in  -(e op e)  can be dropped
| if the priority of  op  is > 6; and in  (-e) op e  if the priority of
| right or non-assoc  op  is < 6, or for a left assoc op its priority
| is <= 6; and in  e op (-e)  if op has priority < 6.)

I strongly agree with this one.  In fact, I recall that I proposed the
same thing (that prefix minus gets whatever syntactic precedence infix
minus does) some time ago and that the rest of the committee agreed to
it.  (Or at least, no one disagreed.)  Somehow, it seems, this didn't
get into the Report.  Can we please fix this?

--Joe



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic