From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA04552; Sat, 5 Apr 2003 22:55:07 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA04509 for ; Sat, 5 Apr 2003 22:55:06 +0200 (MET DST) Received: from mail.eecs.harvard.edu (bowser.eecs.harvard.edu [140.247.60.24]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h35Kt3903498 for ; Sat, 5 Apr 2003 22:55:05 +0200 (MET DST) Received: by mail.eecs.harvard.edu (Postfix, from userid 32210) id D65DD54C46D; Sat, 5 Apr 2003 15:55:00 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.eecs.harvard.edu (Postfix) with ESMTP id D3AAE54C46B; Sat, 5 Apr 2003 15:55:00 -0500 (EST) Date: Sat, 5 Apr 2003 15:55:00 -0500 (EST) From: Michael Tucker To: sergey dyshel Cc: caml-list@inria.fr Subject: Re: [Caml-list] How can I simulate dynamic types in OCaml? In-Reply-To: <20030404115842.87369.qmail@web41213.mail.yahoo.com> Message-ID: References: <20030404115842.87369.qmail@web41213.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; tucker:01 mtucker:01 caml-list:01 char:01 well-typed:01 sergey:99 bug:01 faq:01 beginner's:01 beginners:01 bin:01 caml-bugs:01 ocaml:01 caml:01 center:98 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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