From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <199607240844.KAA21840@pauillac.inria.fr>
Subject: Re: Language improvements (?)
To: christo@nextsolution.co.jp (Frank Christoph)
Date: Wed, 24 Jul 1996 10:44:17 +0200 (MET DST)
In-Reply-To: <9607240630.AA00506@sparc3.nextsolution.co.jp> from "Frank Christoph" at Jul 24, 96 03:30:32 pm
> Third, since the trend in O'Caml is toward curried function types, it would
> be useful to be able to section binary operators as in Haskell, e.g., "(1+)"
> would mean "(function x -> 1 + x)".
Wao! Is this so useful ?
> And, at the risk of instigating a syntax war, I would prefer a more
> Haskell-like syntax overall; for example, offside scoping,
By ``offside scoping'', you mean a ``where'' construct, I presume ?
> uppercase types so
> there is no need for quotes in front of type variables,
No, no, we already exhausted uppercase conventions with modules, constructors,
labels, and let bound identifiers. You may add one more convention to
get rid of the ' for type variables, but it cannot be as trivial as
just ``the first character is lower (resp. upper) case''. You need
something a bit more complex, for instance ``the LAST character must
be lower (resp. upper) case'' (with the side condition ``the
identifier must be at least 2 characters long''. I prefer to write
some ' here and there in my programs.
> and user-definable
> symbolic binary operators... <sigh> Then again, I guess there's no point in
> turning O'Caml into an eager Haskell. Anyway, I suppose there is a
> philosophical reason why there are no user-defined symbolic identifiers in
> Caml although SML allows them.
I don't know exactly what you mean by a ``symbolic identifier'', if
you mean an identifier entirely made of characters that are not
letters or parens (e.g. ++ or <=> or >>), then Caml support it.
These identifier are infix operators, and their precedence is the same
as the precedence of the operator corresponding to the first character
(e.g. +* gets precedence of +).
For instance you may like to define your own << operator as in C:
Objective Caml version 1.01
#let (<<) x y = x lsl y;;
val << : int -> int -> int = <fun>
#1 << 4;;
- : int = 16
Or with a more imperative point of view:
#let (+=) r x = r := !r + x;;
val += : int ref -> int -> unit = <fun>
#let r = ref 0 in r += 2; !r;;
- : int = 2
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis