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,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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 373BCBC0B for ; Sun, 14 Jan 2007 18:59:24 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0EHxNje030485 for ; Sun, 14 Jan 2007 18:59:23 +0100 Received: by wr-out-0506.google.com with SMTP id 69so815614wra for ; Sun, 14 Jan 2007 09:59:23 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YCVcJAF4MEtoFj8ve3XakZ3Z5Bw00K4s0vnvcdZyeCaUBzpqbd8Btzf7FaRePOjdAxL9ZiT9nOv9CAUJkEFZv3TrB4D5TFbfprBzHL78k48OiXFEMB2U7H5LgnZQ+dcORUjWMV9rWIgRGZHVwRPi4xSEZuhZRvZxMod4Pzd8GFs= Received: by 10.90.116.6 with SMTP id o6mr2158102agc.1168797562881; Sun, 14 Jan 2007 09:59:22 -0800 (PST) Received: by 10.90.71.19 with HTTP; Sun, 14 Jan 2007 09:59:22 -0800 (PST) Message-ID: <6ebe51ce0701140959u1314dfaevccbf27ca6de4feee@mail.gmail.com> Date: Sun, 14 Jan 2007 18:59:22 +0100 From: ketty To: "Edgar Friendly" Subject: Re: [Caml-list] Ocaml compiler features Cc: caml-list@yquem.inria.fr In-Reply-To: <45AA69FF.4010802@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45A87011.8080203@gmail.com> <45AA69FF.4010802@gmail.com> X-j-chkmail-Score: MSGID : 45AA6F7B.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45AA6F7B.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 hashtbl:01 syntax:01 hashtables:01 hashtbl:01 ketty:98 edgar:98 zack:01 wrote:01 syntactic:01 caml-list:01 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