Article View: comp.lang.functional
Article #492Re: A question about types in ML
From: Nick Rothwell
Date: Mon, 12 Nov 1990 12:45
Date: Mon, 12 Nov 1990 12:45
34 lines
1799 bytes
1799 bytes
In article <paula.658247771@shum>, paula@SHUM.HUJI.AC.IL (Paula Ross) writes:
> Is there any way in ML that you can create a data type which accepts
> sequences of objects of different types (when the number and types of the
> objects are not known in advance) ?
When they *are* known in advance, then you can use a datatype as a variant
record (essentially):
datatype Object = INTEGER of int
| STRING of string
| ...
If you don't know how many cases you need in advance, then ML is (in
theory) capable of expressing open-ended datatypes that you can add to.
This is currently only available for the built-in type "exn" (the type
of exceptions), so:
exception A and B of int;
val list = [A, B 4];
exception C of string;
val list = (C "Hello") :: list;
(A is a constructor of type exn, B has type int -> exn).
But, since you have to introduce a new constructor for each new type you
wish to work with, you have to retain the constructor in order to take
a value apart for that type.
--
Nick Rothwell, Laboratory for Foundations of Computer Science, Edinburgh.
nick@lfcs.ed.ac.uk <Atlantic Ocean>!mcsun!ukc!lfcs!nick
~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
"Now remember - and this is most important - you must think in Russian."
Technical Details
Message-ID:
<1731@skye.cs.ed.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!edcastle!cs.ed.ac.uk!cs.edinburgh.ac.uk!nickReferences:
<paula.658247771@shum>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!edcastle!cs.ed.ac.uk!cs.edinburgh.ac.uk!nick From: nick@cs.edinburgh.ac.uk (Nick Rothwell) Newsgroups: comp.lang.functional Subject: Re: A question about types in ML Message-ID: <1731@skye.cs.ed.ac.uk> Date: 12 Nov 90 12:45:01 GMT References: <paula.658247771@shum> Sender: nnews@cs.ed.ac.uk Reply-To: nick@lfcs.ed.ac.uk Distribution: comp Organization: Wavetables 'R' Us Lines: 34