Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] raise extra arg ignored
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xleroy@p...>
Subject: Re: [Caml-list] raise extra arg ignored
> failwith "foo" "bar"
> failwith "foo"
> 
> are equivalent. 
> 
> exception Foo;;
> raise Foo 1
> raise Foo
> 
> same for this.

Yes.  For additional fun, you could do
        print_string (raise Foo);;
        print_int (raise Foo);;
        raise Foo + 2;;

Notice that this also works for certain non-terminating functions:
        let rec f() = f();;
        f () "bar";;
        print_string (f());;
        print_int (f());;
        f() + 2;;

> I understand why it typechecks, but couldn't there be a special
> check for this since it can't be useful (or can it??)

Possibly, but that would not be easy to do: we'd have to wait until
type inference for the phrase is completed, remember the principal
types inferred for each sub-expression, and apply ad-hoc checks such as
"warn if an expression of principal type 'a ('a being generalizable in
the context) is applied as if it were a function".  This really
doesn't fit well in the current OCaml type inference technology.

- Xavier Leroy
-------------------
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