Browse thread
Scripting in ocaml
[
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: | 2006-12-22 (18:16) |
From: | skaller <skaller@u...> |
Subject: | Re: strong/weak typing terminology (was Re: [Caml-list] Scripting in ocaml) |
On Fri, 2006-12-22 at 17:51 +0100, Tom wrote: > > Later he gives the following chart > > |Statically checked | Dynamically checked > ------------------------------------------------- > safe | ML, Haskell, Java, etc. | Lisp, Scheme, Perl, > Postscript, etc > unsafe | C, C++, etc. | > > > But this chart is not expressive enough... It is also unclear what you mean by 'unsafe'. Ocaml is not safe: let a = Array.create 0 0 in let y = a.[99] in (* WOOPS *) The fact that an exception is thrown may or may not make the language safe depending on whether or not you INTEND to trigger an exception. The best you can say is that if you don't catch it, its a bug. Otherwise, you have to read the comments to know if the out of bounds access was deliberate .. something compilers can't do very easily. In fact C arrays are safer precisely because the behaviour is not defined. That way you KNOW an out of bound access is an error, so reasoning about the code .. and optimising it .. is easier. Furthermore you can always enable array bounds checking with an instrumentation switch or tool like Purify. Well array bounds probably aren't contentious: most people would say an access violation was a bug, even in Ocaml. But you can't be so sure with try Some (Hashtbl.find table key) with Not_found -> None That doesn't look like a bug, if the key isn't found. There's a difference in intent .. but the language fails to express it. Exceptions and specified dynamic checks are 'evil' :) -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net