Version française
Home     About     Download     Resources     Contact us    
Browse thread
Why doesn't ocamlopt detect a missing ; after failwith statement?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement?
On Fri, 2004-11-26 at 20:01, Richard Jones wrote:
> Thanks everyone for the explanation, and the rather convoluted
> discussion of the type system, which I don't really understand.
> 
> I'd just like to add that this error bit me in a real program, and it
> would be nice if OCaml detected this common case and warned about it:
> 
>   if cond then (
>     ...
>     raise Exn
>   )
>   next_stmt       <-- catastrophic failure, because this statement
>                       is silently ignored


This happens too, and seems harder to catch with the
intertwined procedural/functional coding style:

if cond then
   x ..
   y ... <-- woops, executed unconditionally
;
next

In Felix I do this:

if cond then something else something_else endif;

where the 'else' and 'endif' are both mandatory. For procedural
conditionals I have distinct syntax:

if cond do foo; bah; done;

Both constructions are LALR1 and unambiguous.
Note the if/then/else/endif is purely functional,
the displayed statement is equivalent to

val f: unit -> void = 
  if cond then something else something_else endif
;
f();

The ocaml notation is more compact but less safe.
Camlp4 could fix this I think, perhaps the 
revised syntax already does?

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net