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=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id CFC28BBAF for ; Tue, 7 Apr 2009 09:41:33 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnsCAOOg2knRVdq0kGdsb2JhbACVaD8BAQEBCQkMBxEDphCPFgEDAQOEDAaGDA X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27185475" Received: from mail-bw0-f180.google.com ([209.85.218.180]) by mail1-smtp-roc.national.inria.fr with ESMTP; 07 Apr 2009 09:41:33 +0200 Received: by bwz28 with SMTP id 28so2054614bwz.9 for ; Tue, 07 Apr 2009 00:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=q/KsOUpF6c8YuFPqaCO4+A9AIR3aOkPEbysbgSDuL9s=; b=DQlwxNHmvgET1/AURF3t2lgfSa14ZcVcuXFD1zBqIdSWI8Ic+2UrbbClI95EjLrTDL kp9C0SVt8U3XpViu8TIwNMGeEoV0z41+E5fJPcvA+stdjl7iSIxUjKPODccywID23+q3 MNMJrXVs1sPbaTnNUQbVLh7PF8hcOHT6EdJ38= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=InNDcUkvIe+EratW2owWiSiL/sSDBlQ/LugDx2/l1jXCOU1/saCRWvqOh3POVkNKjG MZJ1NIfV1rznoVlh2j2pGY0gocaVDYEQD7ZMwYi0yqo5MD6tMEqIXEH9PMvWZumzttGi apFhOmMiPw7qnPuHCu1LfZLr/TvUDQzJjuoIM= MIME-Version: 1.0 Sender: david.mentre@gmail.com Received: by 10.239.162.74 with SMTP id k10mr126938hbd.42.1239090092964; Tue, 07 Apr 2009 00:41:32 -0700 (PDT) In-Reply-To: <873aclf1z8.fsf@frosties.localdomain> References: <873aclf1z8.fsf@frosties.localdomain> Date: Tue, 7 Apr 2009 09:41:32 +0200 X-Google-Sender-Auth: d843dc6456329284 Message-ID: <3d13dcfc0904070041l5d59ec76nc97643fc862f334c@mail.gmail.com> Subject: Re: [Caml-list] Subtyping From: David MENTRE To: Goswin von Brederlow Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; subtyping:01 ocaml:01 ocaml:01 associative:01 hashtbl:01 val:01 hashtbl:01 abstr:01 2009:98 48,:98 0.6:98 wrote:01 caml-list:01 pairs:01 short:01 Hello, On Tue, Apr 7, 2009 at 07:48, Goswin von Brederlow wrote: > In the last 2 weeks I've been playing around with lots of different > ways to do the same thing to get a feel for what style suites me > best. If you have improvements or alternative ways of doing the two > things below let me know. Well, if you are learning OCaml, I would advise you to read regular OCaml code, e.g. the standard library. You'll learn The Right OCaml Style(tm). > Lets look another thing going in a similar direction. I want to > have a structure where I can store key value pairs. But just for fun > lets say I want to store values of different types and the key knows > the type of value. In short a heterogeneous associative container: Well, why don't you just do: # type k = Int_k of int | Float_k of int;; type k = Int_k of int | Float_k of int # type v = Int_v of int | Float_v of float;; type v = Int_v of int | Float_v of float # let h = Hashtbl.create 3;; val h : ('_a, '_b) Hashtbl.t = # Hashtbl.add h (Int_k 3) (Int_v 4);; - : unit = () # Hashtbl.add h (Float_k 5) (Float_v 0.6);; - : unit = () Yours, d.