Re: Suggestions

Pierre Weis (weis@pauillac.inria.fr)
Wed, 13 Sep 1995 17:11:31 +0200 (MET DST)

From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <199509131511.RAA29007@pauillac.inria.fr>
Subject: Re: Suggestions
To: raffalli@cs.chalmers.se (Christophe Raffalli)
Date: Wed, 13 Sep 1995 17:11:31 +0200 (MET DST)
In-Reply-To: <199509130815.KAA21297@waldorf.cs.chalmers.se> from "Christophe Raffalli" at Sep 13, 95 10:15:57 am

> 1) there should be a warning when raise got more than one argument.

The problem is due to the raise primitive that returns a polymorphic
argument, which can be applied to anything. It can be exemplified by:

#raise Not_found map it_list;;
Exception non rattrapée: Not_found

I'm sorry to refer once more to Caml V3.1, but here you get:

CAML (decstation) (V3.1.2) by INRIA Thu Feb 4

#raise Not_found map it_list;;

line 1: ill-typed phrase, the variable Not_found of type exc
cannot be used with type instance 'a -> exc in
raise Not_found map it_list
1 error in typechecking

Typecheck Failed

This is due to the syntactic treatment of ``raise'': in this version
of Caml, raise is a keyword and applications of raise are treated
explicitely in the parser.

Now, ``raise Not_found map it_list'' is parsed as
raise (Not_found map it_list). For instance:

#raise failure "foo";;

Evaluation Failed: failure "foo"

This has some drawbacks, since you have to be aware of this special
treatment of raise, when this is just the regular syntactic rule for
application in Caml Light. On the other hand, to treat raise as a
regular primitive leads to very strange programs, since you can
redefine raise.

You may have turned your puzzle as: find out why this program evaluates to ()

#if true then raise Not_found;;
- : unit = ()

Yes, that's because I redefined raise as:

#let raise _ = ();;
raise : 'a -> unit = <fun>

> 2) A "match" guard would be really useful in pattern matching.

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

Why don't you use the ``when'' clauses of Caml Light 0.7?

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

Pierre Weis
----------------------------------------------------------------------------
WWW Home Page: http://pauillac.inria.fr/~weis
Projet Cristal
INRIA, BP 105, F-78153 Le Chesnay Cedex (France)
E-mail: Pierre.Weis@inria.fr
Telephone: +33 1 39 63 55 98
Fax: +33 1 39 63 53 30
----------------------------------------------------------------------------