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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 76F9CBC69 for ; Wed, 17 Oct 2007 16:25:28 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKO3FUfDuhJAjGdsb2JhbACOTgIBCAQGCQYa X-IronPort-AV: E=Sophos;i="4.21,289,1188770400"; d="scan'208";a="18139617" Received: from mail17.bluewin.ch ([195.186.18.64]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 Oct 2007 16:25:28 +0200 Received: from [192.168.1.58] (85.2.109.248) by mail17.bluewin.ch (Bluewin 7.3.121) id 470A8A3800230F92; Wed, 17 Oct 2007 14:25:27 +0000 In-Reply-To: <932096.75090.qm@web54602.mail.re2.yahoo.com> References: <932096.75090.qm@web54602.mail.re2.yahoo.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: caml-list@yquem.inria.fr Content-Transfer-Encoding: 7bit From: =?ISO-8859-1?Q?Daniel_B=FCnzli?= Subject: Re: [Caml-list] Smells like duck-typing Date: Wed, 17 Oct 2007 16:25:40 +0200 To: Dario Teixeira X-Mailer: Apple Mail (2.752.2) X-Spam: no; 0.00; bunzli:01 buenzli:01 statically:01 sig:01 val:01 val:01 struct:01 abstract:01 caml-list:01 constraint:01 int:01 variant:02 data:02 data:02 epfl:02 Use a record with a phantom type (the type must be abstract for this to work). The record has the common properties as fields and a data field which is either a list of tagged values (if many kinds of stories share the same fields) or a variant for the data specific to a kind of story. If there are operations that are allowed only on some kind of stories constrain the phantom type in the signature to enforce this statically. Best, Daniel module Story : sig type 'a t constraint 'a = [< `Full | `Blurb | `Fresh ] (* Story creators *) val full : ... -> `Full t val blurb : ... -> `Blurb t val fresh : ... -> `Fresh t val print_meta_data : [< `Full | `Blurb ] t -> unit end = struct type 'a t = { id : int; title : string; intro : string; data : ... } ... end