English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
RE: Proposal for study: Add a categorical Initial type to ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-10-19 (17:25)
From: Manuel Fahndrich <maf@m...>
Subject: RE: Proposal for study: Add a categorical Initial type to ocaml

I was comparing using Obj.magic in the particular case of writing an
extensible array module vs. adding uninitialized values to the language.

In the second case, having uninitialized values as a language feature will
make code more brittle since the uninitialized exception may be raised
anywhere in the code where a field access is made.

In the first case, the module can be constructed such that the use of
Obj.Magic can be deemed safe, namely by requiring all accesses of extensible
arrays to go through the module and that appropriate checks are in place


-----Original Message-----
From: skaller [mailto:skaller@maxtal.com.au]
Sent: Sunday, October 17, 1999 2:19 AM
To: Manuel Fahndrich
Cc: caml-list@inria.fr
Subject: Re: Proposal for study: Add a categorical Initial type to ocaml

Manuel Fahndrich wrote:
> I did not word what I meant correctly. 

	i thought you did OK ..

>In the case of initial values, errors
> can occur anywhere in the code, namely, whenever I access an uninitialized
> value. Since these values can live in records, and the records can be
> around, the error can occur anywhere.
> Now, with a well-defined and encapsulated use of Obj.magic, such errors
> be avoided. E.g. in the extensible array case, I can write the module in
> such a way that no matter what code I write outside of that module (not
> using Obj.magic), it cannot result in an error.

	I'm sorry. I do do not follow. You argument is comparative,
and appears unsound because it fails to make a distinction.
The magical encapsulation of Obj.magic within a module
or class, can be applied to initials just the same: maintaining
the invariant 'uninitialised values are initialised before use'
is the same in both cases, only the value representing it differs.
Where 'initial' might be used, obj.magic could be used too.
References to both may be propagated without error
(and indeed that is the whole point): the only difference
is that using an initial value is guarranteed to cause
an exception to be raised, whereas using a magical
value offers no guarrantees, and could core dump.

	The initial value is therefore easier
to debug. The other difference seems to be that it
is polymorphic whereas obj.magic needs explicit
John Skaller, mailto:skaller@maxtal.com.au
1/10 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
downloads: http://www.triode.net.au/~skaller