caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Syntax
@ 2002-02-05 14:18 Gerard Huet
  2002-02-05 14:49 ` Markus Mottl
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Gerard Huet @ 2002-02-05 14:18 UTC (permalink / raw)
  To: caml-list

At 13:05 05/02/02 +0100, Daniel de Rauglaudre wrote: 
>Hi, 
> 
>On Tue, Feb 05, 2002 at 12:53:39PM +0100, Remi VANICAT wrote: 
> 
>> So the fact that a library or a tool is written in revised or 
>> standard library doesn't change anything for those who use it. The 
>> only problem is for those who want to change the source, but it's 
>> not so hard to learn this syntax if you want to use it. 
> 
>Exactly.
Yessir. 
It is trivial to switch to revised syntax. It will take you one week to 
get used to True/False vs true/false, to use square brackets in [x :: l], 
and to write (list int) instead of (int list). I never missed the double 
semicolon, and many problems will ill-parenthesised matches just went into 
oblivion. What I missed most is that you can't anymore step through the 
toplevel with mouse cut-and-paste, because the inner let's are not accepted 
at toplevel, you have to write the godamn "value" keyword instead.
Until recently there was no point in pushing the revised syntax, because it 
was very hard to teach the language when the system's printer used another 
syntax than what you typed in. Now that there is smooth integration of 
camlp4 with ocaml with the 3.04, there is no excuse not to use the much 
superior revised syntax, in my opinion. Which does not mean that there 
should be a big concerted effort to switch all our code from one syntax to 
the next. 
I am currently developing a computational linguistics platform in ocaml, now
around 12000 loc in about 50 modules, mostly in revised syntax, some others 
borrowed from other sources or mechanically produced and still in vanila 
syntax, so what. The makefile does what is needed, and I never have any 
problem reading other people's programs from libraries or the hump, etc. 

The crucial point is that we need good tutorials, reference manuals, and
books 
in the revised syntax before being serious about "standardizing" in something 
else than the usual syntax. Once this material exists, then we can talk. 

Let me tell you about an experience I did recently, in using Ocaml as a 
publication language. In the first version of my paper, I said "we shall 
use as algorithmic meta-language OCaml under so-called revised syntax". 
Now one referee got very interested in the code, tried it on his machine
with ocaml 3.02, missed my remark about revised syntax, and said "it is too
bad these are not real programs which people can directly use". Another
referee got completely turned off by the code and said "remove all
proselytism about this weird Ocaml stuff, and use some pidgin algorithmic
language". Typical dilemna. 

What I ended up was writing a short presentation of an algorithmic 
meta-language which I called "Pidgin ML", without any proselytism about 
existing programming languages; it is only in the evaluation part of the 
paper that I reveal that Pidgin ML can be compiled and executed as such by
OCaml+Camlp4. So everybody is happy !

Just as a short plug for revised syntax, here is my introduction:
____________________________________

We shall use as {\sl meta language} for the description of our algorithms 
a pidgin version of the functional language ML. Readers familiar with ML 
may skip this section, which gives a crash overview of its syntax and 
semantics.

The core language has types, values, and exceptions. 
Thus, \verb:1: is a value of predefined type \verb:int:, whereas 
\verb:"CL": is a \verb:string:. 
Pairs of values inhabit the corresponding product type. Thus: 
\verb|(1,"CL") : (nat * string)|. 
Recursive type declarations create new types, 
whose values are inductively built from the associated constructors. 
Thus the Boolean type could be declared as a sum by: 
\verb:type bool = [True | False];:\\ 
Parametric types give rise to polymorphism. 
Thus if \verb:x: is of type \verb:t: and \verb:l: is of type 
\verb:(list t):, we construct the list adding \verb:x: to \verb:l: 
as \verb|[x :: l]|. The empty list is \verb:[]:, of (polymorphic) type 
\verb:(list 'a):. Although the language is strongly typed, explicit type 
specification is rarely needed from the designer, since principal types 
may be inferred mechanically.

The language is functional in the sense that functions are first class 
objects. Thus the doubling integer function may be written as 
\verb:fun x -> x+x:, and it has type \verb:int -> int:. It may be associated 
to the name \verb:double: by declaring: \verb:value double = fun x -> x+x;:\\ 
Equivalently we could write: \verb:value double x = x+x;:\\ 
Its application to value \verb:n: is written as \verb:(double n): or even 
\verb:double n: when there is no ambiguity. Application associates to the 
left, and thus \verb:f x y: stands for \verb:((f x) y):. 
Recursive functional values are declared with the keyword \verb:rec:. 
Thus we may define the factorial function as:\\ 
\verb:value rec fact n = n*(fact (n-1));:\\ 
Functions may be defined by pattern matching. Thus the first projection of 
pairs could be defined by:\\ 
\verb:value fst = fun [ (x,y) -> x ];:\\ 
or equivalently (since there is only one pattern in this case) by:\\ 
\verb:value fst (x,y) = x;:\\ 
Pattern-matching is also usable in \verb:match: expressions which generalise 
case analysis, 
such as: \verb:match l with [ [] -> True | _ -> False ]:, which 
tests whether list \verb:l: is empty, using underscore as catch-all 
pattern.

Evaluation is strict, which means that \verb:x: is evaluated before 
\verb:f: in the evaluation of \verb:(f x):. The \verb:let: expressions 
permit to sequentialise computation, and to share sub-computations. Thus 
\verb:let x = fact 10 in x+x: will compute \verb:fact 10: first, 
and only once. 
An equivalent postfix \verb:where: notation may be used as well. Thus 
the conditional expression \verb:if b then e1 else e2: is equivalent to: 
\verb:choose b where choose = fun [ True -> e1 | False -> e2]:.

Exceptions are declared with the type of their parameters, like in: 
\verb:exception Failure of string;:
An exceptional value may be raised, like in: 
\verb:raise (Failure "div 0"): and handled by a \verb:try: switching on 
exception patterns, such as:
\verb:try expression with [ Failure s -> ... ]:.
Other imperative constructs may be used, such as 
references, mutable arrays, while loops and I/O commands, 
but we shall seldom need them. Sequences of instructions are 
evaluated in left to right regime in \verb:do: expressions, such as: 
\verb:do {e1; ... en}:. 

ML is a {\sl modular} language, in the sense that sequences of type, value 
and exception declarations may be packed in a structural unit called a 
\verb:module:, amenable to separate treatment. 
Modules have types themselves, called {\sl signatures}. Parametric 
modules are called {\sl functors}. The algorithms presented in this paper 
will use in essential ways 
this modularity structure, but the syntax ought to be self-evident.

Readers uninterested in computational details may think of ML 
definitions as recursive equations over inductively defined algebras. Most 
of them are simple primitive recursive functionals. 
___________________________________________________
At this point, note that Pidgin ML has no objects (not even records!) nor
labels.

And later on I spill the beans:
Pidgin ML definitions may actually be directly executed as Objective Caml 
programs \cite{ocaml}, under the so-called revised syntax \cite{camlp4}. 

>> By the way, is there any caml-mode for Emacs and the revised syntax ? 
> 
>I don't think so but there is a request for that (Gérard Huet asked 
>me yesterday). I use a very old caml-light-or-what emacs mode and I 
>am too lazy to look at emacs-lisp to create my mode.

This is an important point. I myself use a slighly hacked version of Tuareg 
as an interim solution. I shall have a look at otags, which, being built 
with camlp4 support, ought to be parametrizable (?).

I suggest this syntax problem should be seriously considered, but as a 
long-term effort, encompassing development tools and documentation and 
training material. This is not a battle that can be won by one round of 
email flame.

Gerard


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [Caml-list] syntax
@ 2002-02-05 21:47 Michael Vanier
  2002-02-06 12:24 ` Daniel de Rauglaudre
  2002-02-06 12:53 ` Achim Blumensath
  0 siblings, 2 replies; 10+ messages in thread
From: Michael Vanier @ 2002-02-05 21:47 UTC (permalink / raw)
  To: caml-list


I've looked at the revised syntax, and I like most of what I see (except
for the use of x.val instead of !x).  One question: how many shift-reduce
conflicts does the revised syntax have?  

Mike
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <3C60E263.D2E35B3A@tsc.uc3m.es>]
[parent not found: <200202061059.g16Ax2n25555@concorde.inria.fr>]
* Re: [Caml-list] Threats on future of Camlp4
@ 2002-10-11 11:34 Kontra, Gergely
  2002-10-11 16:36 ` [Caml-list] Syntax brogoff
  0 siblings, 1 reply; 10+ messages in thread
From: Kontra, Gergely @ 2002-10-11 11:34 UTC (permalink / raw)
  Cc: caml-list

>I want to make my contribution to this flamewar short:
>
>  * Camlp4 is useful.

>Otherwise, please resolve personal issues over a beer in a bar or in a
>fight outside, whichever you prefer. As long as all of you stay healthy
>for further development, OCaml-users will be happy... ;-)

I agree, camlp4 IS useful. (Exploring the alternative syntax)
I just afraid of developing in ocaml, if there exists two version of the
syntax. Sorry to say, but I cannot say much clever about this issue, but
I think the main goal is to have ONE version of syntax, which is clean.
But I know many people used to the old syntax, so I really
don't know how to handle it. As a newbie to ocaml, I found, that the
alternative syntax helps us to write correct code (but to tell the truth
I don't agree with some of the decisions... Eg. it uses value, not val,
explaining ocaml syntax doesn't have abbreviated keywords. But it does
have! The fun keyword, which is not called function. Anyway, this is not
a bad thing, since SML use fun also, so I think one can have val, which
is exactly the same in SML.
Another thing, that
bothers me is the do { } syntax. It seems a bit silly mixture of some
shell and C syntax, I think either do ... done or { ... } would be a
good choice (or support both, this way bash and C programmers will be
happy ;))
Ok, I know, you'll say: "Then why don't you write your own syntax?"

Ooops, so I'd like to know what is the tendecy: will the alternative
syntax be a new standard, or users should use the old syntax, and the
alternative syntax supporting is their problem?

ps: If this was discussed, please tell me where can I read it.

Gergo

+-[Kontra, Gergely @ Budapest University of Technology and Economics]-+
|         Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |
|  URL:   turul.eet.bme.hu/~kgergely    Mobile: (+36 20) 356 9656     |
+-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-10-11 16:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-05 14:18 [Caml-list] Syntax Gerard Huet
2002-02-05 14:49 ` Markus Mottl
2002-02-05 15:16 ` Jean-Francois Monin
2002-02-05 17:51 ` Diego olivier FERNANDEZ PONS
2002-02-05 21:47 [Caml-list] syntax Michael Vanier
2002-02-06 12:24 ` Daniel de Rauglaudre
2002-02-06 12:53 ` Achim Blumensath
     [not found] <3C60E263.D2E35B3A@tsc.uc3m.es>
2002-02-06 10:08 ` [Caml-list] Syntax Diego olivier FERNANDEZ PONS
     [not found] <200202061059.g16Ax2n25555@concorde.inria.fr>
2002-02-06 12:09 ` Diego olivier FERNANDEZ PONS
2002-10-11 11:34 [Caml-list] Threats on future of Camlp4 Kontra, Gergely
2002-10-11 16:36 ` [Caml-list] Syntax brogoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).