* [Caml-list] How can I simulate dynamic types in OCaml?
@ 2003-04-04 11:58 sergey dyshel
2003-04-05 20:55 ` Michael Tucker
2003-04-05 20:58 ` Sven Luther
0 siblings, 2 replies; 3+ messages in thread
From: sergey dyshel @ 2003-04-04 11:58 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] How can I simulate dynamic types in OCaml?
2003-04-04 11:58 [Caml-list] How can I simulate dynamic types in OCaml? sergey dyshel
@ 2003-04-05 20:55 ` Michael Tucker
2003-04-05 20:58 ` Sven Luther
1 sibling, 0 replies; 3+ messages in thread
From: Michael Tucker @ 2003-04-05 20:55 UTC (permalink / raw)
To: sergey dyshel; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] How can I simulate dynamic types in OCaml?
2003-04-04 11:58 [Caml-list] How can I simulate dynamic types in OCaml? sergey dyshel
2003-04-05 20:55 ` Michael Tucker
@ 2003-04-05 20:58 ` Sven Luther
1 sibling, 0 replies; 3+ messages in thread
From: Sven Luther @ 2003-04-05 20:58 UTC (permalink / raw)
To: sergey dyshel; +Cc: caml-list
On Fri, Apr 04, 2003 at 03:58:42AM -0800, 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?
Use a list of variants ?
type element = A of a | B of b | C of c | D of d | ...
type liste = element list
You have to check the appropriate variant each time (or most time) you
use it, but after all, you wanted dynamic type checking.
Friendly,
Sven Luther
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-04-05 20:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-04 11:58 [Caml-list] How can I simulate dynamic types in OCaml? sergey dyshel
2003-04-05 20:55 ` Michael Tucker
2003-04-05 20:58 ` Sven Luther
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox