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.3 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 36C87BBAF for ; Sat, 23 Aug 2008 14:50:31 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIBAJOkr0hKfSwdlGdsb2JhbACRbD4BAQEBCQMKBxEDmlaHBAECgyU X-IronPort-AV: E=Sophos;i="4.32,258,1217800800"; d="scan'208";a="16388588" Received: from yx-out-2324.google.com ([74.125.44.29]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Aug 2008 14:50:30 +0200 Received: by yx-out-2324.google.com with SMTP id 3so475086yxj.3 for ; Sat, 23 Aug 2008 05:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=Q2CJAwztrdWqNerEOGjpCb/g2PvyGAqOzVp/POwpaz8=; b=U0PoJgK6a1l8QR6rOJoF/cpiSCHaevSXl08OhFFM1Q/7bJ+QCupkxf32CxiOr4B04k F9JTgpqtbh78CQQacARWhD65vEYVtFUlB6H0cycIAewEy8PUzfPBP9i4LKvdqp/ZxpFa 8KbNDFEhgsI+ra8+BKLZyqFpbBC+DPvgt0j1o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=tqSA0w1tEHDzTvcjD8wTUCbihOo9EHHHsL3QohczXupinROcIGNViszHce+R9XggTP zPeI8rQexaVngERwXXTxQCAgnjhatd6E7X0vUiTTyS1dMjJ42YDblf0AJGir66/7rCsC IxsANnXYVQ24OgBYkyOC20NRrJiK9R+h0OfOo= Received: by 10.150.146.1 with SMTP id t1mr3602865ybd.81.1219495829567; Sat, 23 Aug 2008 05:50:29 -0700 (PDT) Received: from ?192.168.0.102? ( [24.99.180.210]) by mx.google.com with ESMTPS id 9sm3454250yws.5.2008.08.23.05.50.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 23 Aug 2008 05:50:28 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] typeclasses in OCaml Date: Sat, 23 Aug 2008 08:50:22 -0400 User-Agent: KMail/1.9.7 Cc: Jacques Garrigue References: <200808220854.12598.peng.zang@gmail.com> <20080823.115753.85827777.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20080823.115753.85827777.garrigue@math.nagoya-u.ac.jp> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200808230850.27191.peng.zang@gmail.com> X-Spam: no; 0.00; ocaml:01 hash:01 'self:01 ocaml:01 polymorphism:01 recursive:01 inherently:01 peng:98 peng:98 wrote:01 caml-list:01 constructor:01 define:02 garrigue:03 garrigue:03 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 22 August 2008 10:57:53 pm Jacques Garrigue wrote: > There is no way to specify "a 'z version of 'self", and this is the > reason you cannot do this in ocaml. > > Even if you don't require structural polymorphism for your object type > (which you need here, since you want to write #mappable), there are > other difficulties related to recursive types having to be regular. > > A classical workaround is to define map as a function using #fold and > cons: > > let map cons f (o : 'a #foldable) = > o#fold (fun x o' -> cons (f x) o') > > Note that for this to work you need #fold to be the correct fold > (i.e. fold_right) > > Hope this helps, > > Jacques Garrigue Yes this has been very helpful. It's good to know I'm not just missing something. I will use your workaround instead. It makes perfect sense. There is nothing inherently special about mappable. It is just a container that we can access the elements of (that's #foldable) and that has a constructor. Thanks, Peng -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFIsAeTfIRcEFL/JewRApXnAKDTDuq97Dfe7/WcIVtFLWfqUeb56QCeKcla a61KJh5dWEnQmHwalusb0Mo= =lP8V -----END PGP SIGNATURE-----