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
[Caml-list] extensible records again
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-21 (16:55)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] extensible records again
On Sun, 2004-03-21 at 17:21, Michael Vanier wrote:

> I've written a dynamically-typed language in ocaml, and I want to be able to
> add new types to the language without having to add new primitive types to
> the system. 

See Felix. The core system has NO primitive types,
not even bool: all primitive types are added by the user
(as bindings to C types).

> Now I want to add a type for (say) files.  I don't want this to be a type
> at the same level as ints or floats, because I want users to be able to add
> their own types to the language without hacking the core type definition.
> I can do this as follows:
>     (* types.mli *)
>     type data =
>         Int of int
>       | Float of float
>       | ...
>       | Extension of exn

You can just use:

	| Extension of string * address

where address is a machine address of some binary
data. What it is is completely irrelevant, since the
operations on user defined primitive data type
can only be specified in one way: by providing
C functions which manipulate that type.

John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners