From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=AWL,MISSING_HEADERS, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 63B94BC0B for ; Sun, 14 Jan 2007 18:36:36 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.234]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0EHaZs3008263 for ; Sun, 14 Jan 2007 18:36:36 +0100 Received: by wr-out-0506.google.com with SMTP id i28so744493wra for ; Sun, 14 Jan 2007 09:36:35 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=m7rLUVWxq3FCMo4YX/sPqCwm0IyvLFTwCkwRQYA4syRPxFSG0DKlyraulY3sBcTGl8Wb/Y2uFthKOdEooO0tT8ejYRDSb4lDWa2toynmu6+EVYoLt6r0HN6WAR636EU4fijK4qOTbCDBbYmEaoHGwGI1GnZF0aoL74xjQQpFxFI= Received: by 10.64.193.8 with SMTP id q8mr4050913qbf.1168796194556; Sun, 14 Jan 2007 09:36:34 -0800 (PST) Received: from ?192.168.0.18? ( [69.155.31.57]) by mx.google.com with ESMTP id f16sm4556894qba.2007.01.14.09.36.33; Sun, 14 Jan 2007 09:36:34 -0800 (PST) Message-ID: <45AA69FF.4010802@gmail.com> Date: Sun, 14 Jan 2007 11:35:59 -0600 From: Edgar Friendly User-Agent: Thunderbird 1.5.0.9 (X11/20061206) MIME-Version: 1.0 Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ocaml compiler features References: <45A87011.8080203@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-j-chkmail-Score: MSGID : 45AA6A23.000 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 45AA6A23.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 arrays:01 type-safe:01 printf:01 iteri:01 printf:01 compiler:01 variants:01 edgar:98 supple:98 computer's:98 wrote:01 caml-list:01 functions:01 Tom wrote: > > you could do it like this instead > > > > let carrot, apple, pizza, coke, sushi = 0, 1, 2, 3, 4 > > > > let in_supple = Array.create 5 0 > > > > in_supply.(coke) <- 20 > > > > . What do you think? > > > > - Tom > > That gives me what I've asked for at the moment, but I really want arrays indexed by atomic variant types in a type-safe way. i.e. so I could do: type food = Carrot | Apple | Pizza | Coke | Sushi let in_supply = Super_array.create food 0 in_supply.(Coke) <- 20 for f in food'range do printf "%s - %d" f'name in_supply.(f) done or even Super_array.iteri (fun f sup -> printf "%s - %d" f'name %d) This will require some magic in the compiler, and some trivially auto-generated functions to get at the names of atomic variants. Yes, I know it could be left to the user to write the boring function: let food_to_string = function Carrot -> "Carrot" | Apple -> "Apple" ... but why should you do the work, if the computer's being paid to do it? E.