Suggestions

Christophe Raffalli (raffalli@cs.chalmers.se)
Wed, 13 Sep 1995 10:15:57 +0200

Date: Wed, 13 Sep 1995 10:15:57 +0200
Message-Id: <199509130815.KAA21297@waldorf.cs.chalmers.se>
From: Christophe Raffalli <raffalli@cs.chalmers.se>
To: caml-light@pauillac.inria.fr
Subject: Suggestions

Hi,

After using Caml-Light (a lot), I think I have few suggestions that might be
worst a discussion:

1) find the bug in this piece of code:

...;
if ... then raise Not_found
f t;
...

You get it ! f t is never called !
Conclusion : there should be a warning when raise got more than one argument.

2) A "match" guard would be really useful in pattern matching: take this
exemple:

a module with :

type A (* abstract type *)
and A' = B | C of A * A;;

value read : A -> A';;

an implementation of a function f

let f x =
match read x with
B -> ...code1...
| C (x1,x2) ->
(match read x1 with
B -> ...code1...
| C _ ->
(match read x2 with
B -> ...code1...
| C _ -> ...code2...
)
)
;;

code1 is there 3 times !

If we use a match guard:

let f x =
match read x with
C(x1,x2) where match read x1, read x2 with C _,C _ -> ...code2...
| _ -> ...code1...
;;

This make it much simpler, and I have plenty of axemple where this would be
usefull ! Moreover, stream pattern matching can be implemented as a syntactic
suggar for the match guard (with a different semantic that the current one).

3) Order of evaluation is unspecified. I have no problem with that except that
some piece of imperative code can behave differently on different
compiler. Such code should not be allowed or at least give a warning. I
propose the following very simple extension of the type system to detect
ambiguities:

Arrows can be marker with a *
(this star does not need to be printed to the user)

The |- in a typing seqent can be marker too.

Then the typing rules are

Gamma , x : A |- t : B
----------------------
Gamma |- \x t : A -> B

Gamma , x : A |-* t : B
----------------------
Gamma |- \x t : A ->* B

Gamma |-r t : A1 ->m1 ... -> An ->mn B Gamma |-p1 u1 : A1 ... Gamma |-pn An
-----------------------------------------------------------------------------
Gamma |-r' (t u1 .. un) : B

with
- r' is star if one of the r m1 .. mn p1 ... pn is star
- if there is more than one argument and if one of the p1 ... pn is star
then an ambiguities warning is printed.

now the type of the function doing physical manipulation is marked:

print_string : string ->* unit
:= : 'a ref -> 'a ->* unit
raise : exn ->* 'a
etc ....

the other function are unchanged.

I think we need something like that ! and I think it is really simple !

Hope this help to have a better language ....
Christophe Raffalli