[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SYNTAX ONLY: A couple of extensions



Date: 29 May 91 22:49
From: haskell-request@cs.glasgow.ac.uk
Sender: Joe Fasel <jhf@c3serve.c3.lanl.gov>
To: haskell <haskell%cs.yale.edu@yalevm.ycc.yale.edu>
Subject: Re: SYNTAX ONLY: A couple of extensions

Original-Via: uk.ac.nsf; Wed, 29 May 91 22:27:58 BST
Original-Sender: jhf%gov.lanl.c3.c3serve%edu.yale.ycc.yalevm@CS.YALE.edu

| Joe proposed two syntax extensions:
|
|    1.  Sections
|    I was once opposed to sections, since they seemed like a frill alongside
|    lambda abstractions.  I have since changed my mind.  ...
|
| I guess I haven't; i.e. I still consider them a frill not worth having
| in the language.  Rationale:
|
| a) Sections are really only useful for the left-hand argument, since
|    instead of the section (x+) you can currently write (+)x.

Actually, you usually have to write ((+)x).  Also this technique
leads you to writing things like ((>=)x), which is a Bad Thing.

| a) I don't think the alternative lambda syntax is much heavier;
|    for example "\x->x+y" compared to "(+y)".  In a large program
|    this difference is lost in the noise.

It makes a big difference if you use a thorough-going higher-order
style, as in Richard Bird's stuff.

| c) If you REALLY don't like lambda syntax you could always write:
|       r(+)y  where  r f x y = f y x         (:-)

Indeed, I have added "flip" to the standard prelude.  It is the C
combinator, like "r" above.  So in place of (1/) for the reciprocal
function, I can write (flip (/) 1).  Wonderful.  ;-)

| b) Although Haskell "doesn't have prefix operators", in reality it
|    has exactly one: prefix minus.  So we have to decide what (-x) means.

We already have a similar problem with (-), which we decided means
(\x y -> x + y), not (\x -> -x), which is why we have "negate".
Miranda similarly provides "neg".  Miranda makes (-x) not a section,
and provides  subtract x y = x - y  to substitute for the section.
Actually, subtract is just (-), but ((-)x) looks too much like (-x),
I guess.

--Joe