Proposal for study: Add a categorical Initial type to ocaml

From: skaller (skaller@maxtal.com.au)
Date: Fri Oct 08 1999 - 18:38:55 MET DST


Date: Sat, 09 Oct 1999 02:38:55 +1000
From: skaller <skaller@maxtal.com.au>
To: caml-list@inria.fr
Subject: Proposal for study: Add a categorical Initial type to ocaml

I would like to propose adding a new special type to ocaml,
a categorical initial type. This type is the categorical dual
of the categorical terminal type, unit.

There proposal is for a syntactic designator (say '$') for the
non-existant value of the initial type, which can
be bound to a variable of any type.
[You could say it has type 'a, as does 'raise SomeException']

The effect of attempting to read this value from any type
should be to raise the exception Uninitialised_value.

Example:

        type A = { data: t }
        let x = { data = $ }
        in x.data (* raises exception *)

        type B = {mutable data: t }
        let y = { data = $ }
        in if something x.data <- t_value;
        x.data (* raise exception if not something *)

The use of initial is something like a Haskell monad
with all types T changed to T option, and all
read acesses changed to

        match t with
        | Some t' -> t'
        | None -> raise Uninitialised_value

A better name than $ is probably 'none'.
Boxed values can use a null pointer for none.
Integers and floats can be treated as follows:
do not initialise them at all, if -unsafe is
specified. Otherwise, use the spare value of integers
and some NaN for floats, and insert tests
for all read accesses.

Chars can be handled too, but it is probably not worth the
effort until they are lifted to ISO10646, which has
suitable code points available. [We could use 0xFF for
8 bit chars]

-- 
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



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:26 MET