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.0 required=5.0 tests=AWL,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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 2F2A5BC69 for ; Wed, 17 Oct 2007 17:26:10 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOfGFUdA6ba6kGdsb2JhbACOTgIBAQcEBBMRB4En X-IronPort-AV: E=Sophos;i="4.21,290,1188770400"; d="scan'208";a="18142276" Received: from nf-out-0910.google.com ([64.233.182.186]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 Oct 2007 17:26:00 +0200 Received: by nf-out-0910.google.com with SMTP id e27so1736307nfd for ; Wed, 17 Oct 2007 08:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=7uD2zR763tQRbXN0RnfLcN5f7VVfG8wA7rJXZEDYFw0=; b=KQS+9ULVaYRW4Mf3GAYifrfib2yYFd7iJ18Xz5U0mnrfzHK+6j0WqsfuuyGWDv2PiNdgpGtQqKI2bfcmNfVK3b7EMutEKOQ+JFFSV47/c/C6eABZhuhZkQz8gJNI7vnOxP3ON9T4ixUI0pJsfk0RLChC954ddJXMJFkIrIREHBo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=joF1uyPmXbt5ot+yH1vfqewKqkS5HGzPr8+b9MiaMulABZFus8nG4LdIKWgn5FaKtdIr2aFdYVH14i93e58M8gaETekfUkFXoaEXgvjUGwixW9RZ790zWagb7pTaiswuCaoYl/MoIt3TUic6vnItrDieM0ZEfi8r4AkM0kbwjCw= Received: by 10.86.97.7 with SMTP id u7mr6912237fgb.1192634759643; Wed, 17 Oct 2007 08:25:59 -0700 (PDT) Received: from ?192.168.0.5? ( [87.88.165.197]) by mx.google.com with ESMTPS id y6sm14394997mug.2007.10.17.08.25.56 (version=SSLv3 cipher=RC4-MD5); Wed, 17 Oct 2007 08:25:57 -0700 (PDT) Message-ID: <47162982.6040009@lix.polytechnique.fr> Date: Wed, 17 Oct 2007 17:25:54 +0200 From: Arnaud Spiwack User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Smells like duck-typing References: <788147.33893.qm@web54602.mail.re2.yahoo.com> In-Reply-To: <788147.33893.qm@web54602.mail.re2.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: Arnaud Spiwack X-Spam: no; 0.00; lix:01 datatype:01 invariants:01 syntax:01 cheers:01 beginner's:01 ocaml:01 bug:01 carbon:98 beginners:01 arnaud:01 arnaud:01 abstract:01 exception:01 exception:01 First, let us emphasize that this goes down to the original "option" thing, but in a more dynamic fashion. It is very possible to wrap it back with phantom types, which would probably be a good idea in this case. My taste for this sort of thing is to make all this a finite map of some sort (might be implemented as a list, but the primitive should ensure a form of unicity, therefore an additional layer of abstract datatype). Then you would need a type to query over : "field_field = [ `Title | `Intro | `Body | `Field ]. Implement a function "fetch" that returns you a field_t or raises an exception (you can do similarily a function "mem" etc). Then you can define let title m = let `Title s = fetch `Title m in s;; and give it type [> `Title ] story -> string (to be sure not to raise an exception, modulo right phantom type invariants). That's my own methodology for this sort of types. Arnaud Spiwack Dario Teixeira a écrit : >> I would use something weaker, and I wouldn't use objects >> either. To me, this is essentially a dynamic scenario, >> so the data type should be dynamic. For example: >> >> type field_t = [ >> | `Title of string >> | `Intro of string >> | `Body of string >> | `Field of string * string >> ] >> >> type story_t = field_t list >> >> > > Hi, > > Interesting idea, but how would you access the fields in a convenient > manner? Note that nothing beats record access (say, story.title) or even > object method call (story#title) in convenience and readability. > > (I guess the convenience aspect could be sorted out with a syntax > extension, but then we're moving into far more complex territory > than I hope is necessary...) > > Cheers, > Dario > > > > > ___________________________________________________________ > Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >