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.2 required=5.0 tests=AWL,MAILTO_TO_SPAM_ADDR, 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 9BB8EBC0B for ; Sun, 14 Jan 2007 19:22:16 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.237]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0EIMF1l020853 for ; Sun, 14 Jan 2007 19:22:16 +0100 Received: by wr-out-0506.google.com with SMTP id 69so818458wra for ; Sun, 14 Jan 2007 10:22:12 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=dLGw7wpWx4se41C5e9v6jujjxrS5bpmnvZ+eLrA/DDluHpEouK5QbESIWJ6JPpxdUyb9eRGCh69GezMHxyhj1mIqDcQWPSNbCmL8lncSgKW/+Bwp1bi8Da7CQ40/XIArWvA6LL1eJgrLyXF7msrXHcIkGKLCd9Fw53KyrQn9LJU= Received: by 10.65.237.19 with SMTP id o19mr4179169qbr.1168798932076; Sun, 14 Jan 2007 10:22:12 -0800 (PST) Received: from ?192.168.0.18? ( [69.155.31.57]) by mx.google.com with ESMTP id e17sm3371176qba.2007.01.14.10.22.11; Sun, 14 Jan 2007 10:22:11 -0800 (PST) Message-ID: <45AA74B0.3070309@gmail.com> Date: Sun, 14 Jan 2007 12:21:36 -0600 From: Edgar Friendly User-Agent: Thunderbird 1.5.0.9 (X11/20061206) MIME-Version: 1.0 To: ketty Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ocaml compiler features References: <45A87011.8080203@gmail.com> <45AA69FF.4010802@gmail.com> <6ebe51ce0701140959u1314dfaevccbf27ca6de4feee@mail.gmail.com> In-Reply-To: <6ebe51ce0701140959u1314dfaevccbf27ca6de4feee@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-j-chkmail-Score: MSGID : 45AA74D7.002 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 45AA74D7.002 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 hashtbl:01 syntax:01 hashtables:01 hashtbl:01 variants:01 edgar:98 ketty:98 edgar:98 zack:01 wrote:01 ketty wrote: > On 1/14/07, Edgar Friendly wrote: >> 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 >> > > What you really want is a mapping from a variant type to elements of > data. We already have the Map and Hashtbl modules for that. Although > it would be nice with some syntactic sugar for dealing with them. > There seems to be an old syntax extension for hashtables here: > http://www.bononia.it/~zack/stuff/hashtbl_ext.ml > Yes to the first sentence, I think no on the second. Map and Hashtbl are very good, but I think I really want an array. For an ('a, 'b) Map, this is for situations where the set of 'a is fixed at design time, I don't see the overhead of Maps and Hashtbls being appropriate. Atomic variants already have unique ids from 0 to n-1, so they seem quite appropriate for this kind of task. E.