Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How can I simulate dynamic types in OCaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Tucker <mtucker@e...>
Subject: Re: [Caml-list] How can I simulate dynamic types in OCaml?
Hi,

  If you have a set of things of different types, but you know the types
ahead of time, then this is possible. You can consider the type of each
item in your set to be a complex type that consists of a flag and the
actual data. You could then make a list of things that have this complex
type. In OCaml, you could define a new type:

type combotype = INT of int | CHAR of char

Plus whatever other types you will allow in your list.

Then, an expression like:

[INT 1, CHAR 'a', INT 2, INT 2, CHAR 'b']

will be well-typed.

Does that help?

Mike

On Fri, 4 Apr 2003, sergey dyshel wrote:

> Hi
>
> I like static type-checking in OCaml but sometimes I
> need to implement some dynamic stuff (like a list of
> values of different types). Is there a way to
> do it in OCaml or at least simulate this?
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - File online, calculators, forms, and more
> http://tax.yahoo.com
>
> -------------------
> 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
>

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