caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Tucker <mtucker@eecs.harvard.edu>
To: sergey dyshel <sdieselil@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How can I simulate dynamic types in OCaml?
Date: Sat, 5 Apr 2003 15:55:00 -0500 (EST)	[thread overview]
Message-ID: <Pine.BSF.4.51.0304051549190.57321@bowser.eecs.harvard.edu> (raw)
In-Reply-To: <20030404115842.87369.qmail@web41213.mail.yahoo.com>

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


  reply	other threads:[~2003-04-05 20:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-04 11:58 sergey dyshel
2003-04-05 20:55 ` Michael Tucker [this message]
2003-04-05 20:58 ` Sven Luther

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.BSF.4.51.0304051549190.57321@bowser.eecs.harvard.edu \
    --to=mtucker@eecs.harvard.edu \
    --cc=caml-list@inria.fr \
    --cc=sdieselil@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).