Version française
Home     About     Download     Resources     Contact us    
Browse thread
environment idiom
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] Re: environment idiom
On Thu, 2004-12-09 at 09:09 +0000, Richard Jones wrote:
> Just an observation here:
> 
> The object method seems to be compile-time safe, whereas the hash
> method seems to require run-time checks which could fail.  Am I right
> in thinking this?  If so, the compile-time safe version is infinitely

What run-time checks?  OCaml is statically typed, it has no run-time
type checking.  Only things like array bounds are checked at run-time.
The hash method is typed similarly to the following:

# let x = ref `A;;
val x : _[> `A ] ref = {contents = `A}
# x := `B;;
- : unit = ()
# x;;
- : _[> `A | `B ] ref = {contents = `B}

However, when using such things in real programs you must specify the
final type explicitly (e.g. in the .mli file) in order to give a
definite type for the variable in the module (since the above obviously
isn't safe across compilation units).