Browse thread
Why doesn't ocamlopt detect a missing ; after failwith statement?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2004-11-26 (19:14) |
From: | Brian Hurt <bhurt@s...> |
Subject: | Re: [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement? |
On 26 Nov 2004, skaller wrote: > On Fri, 2004-11-26 at 08:14, Nicolas Cannasse wrote: > > > All well and good, but I don't understand why it doesn't warn me about > > > the missing ';' in the first case. > > > > val failwith : string -> 'a > > > > so failwith "error" prerr_endline "OK"; > > > > is a valid call since 'a unify with (string -> unit) -> string -> unit > > .. a problem which could not occur were there a void type > which couldn't unify with 'a, and prerr_endline had > type string-> void. > > There is one- it's called unit. And prerr_endline probably already uses it. The problem isn't with prerr_endline, the "problem" is with failwith. failwith needs to return 'a, as it doesn't return. If it returned some other type, I couldn't write code like: if some_test then failwith "some_test" else some_value To make the above expression type correctly, failwith has to return the same type as some_value- which could be anything. Therefor, failwith needs to return 'a, a value which can unify with (be the same type as) anything else. The next problem comes in how Ocaml decides when and to what to apply arguments. Consider the expression: f [1;2;3] Fairly obvious, right? We're calling f with an argument of an int list. Not necessarily. Consider: List.map f [1;2;3] Now f, instead of being the function we're passing arguments into, is now an argument itself. So now, this is exactly the problem we're running into- prerr_endling is being treated exactly like f above- one minor change, and it's getting turned into an argument when it's meant to be a function call. Does this help? Brian