Browse thread
RE: Proposal for study: Add a categorical Initial type to ocaml
-
Manuel Fahndrich
- skaller
[
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: | 1999-10-18 (14:10) |
From: | skaller <skaller@m...> |
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 passed > around, the error can occur anywhere. > > Now, with a well-defined and encapsulated use of Obj.magic, such errors can > 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 casting. -- 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