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.8 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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id AC89DBBC6 for ; Fri, 17 Apr 2009 14:01:39 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag8AAFsM6EnRVYT1oWdsb2JhbACWDT8BAQEBAQEHCQoCBxGnEQeBApASAQMBA4F7gX8GhWM X-IronPort-AV: E=Sophos;i="4.40,204,1238968800"; d="scan'208";a="24744127" Received: from an-out-0708.google.com ([209.85.132.245]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Apr 2009 14:01:39 +0200 Received: by an-out-0708.google.com with SMTP id d14so5182and.27 for ; Fri, 17 Apr 2009 05:01:38 -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=p/FFVOWyahD4nFR9stxXXR8iyUBcQ7HV9tjcob1baqE=; b=W4fKYW7aVfRbawCas1ZlZusr7LA1eAlAeUscE8d82LQqBtfxUh66/ZqmlVnzAva5Na MX8orBsnlhWgjxghmUoUlVRMHCO0epSen7hFOk+DPGceJtjCvbrQ4ezfJVlBj0s22Vvh 4kDQxCFY2pGhmctdkdxef7H/pPwwVgmlie9/s= 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=wVmlKdpybFmpyC8mMfShFYY8W4pQ0FRX0+6z+AuvELJPU8Oaiou0k8NpIolnyFsU9/ Ny6yvYxWaUf2U9vMQyZMR5dGe/AU3ZY4tkpWB5IbbCCOTAj7RxIknOAagupmo32v80j4 sxacuKrGE32IKRzn9P3FK7SOxGI+UZKRRuiLY= Received: by 10.100.7.13 with SMTP id 13mr3742780ang.10.1239969697845; Fri, 17 Apr 2009 05:01:37 -0700 (PDT) Received: from ?192.168.0.102? (c-98-219-43-7.hsd1.ga.comcast.net [98.219.43.7]) by mx.google.com with ESMTPS id c1sm3917825ana.26.2009.04.17.05.01.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 17 Apr 2009 05:01:37 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unable to define a polymorphic map method Date: Fri, 17 Apr 2009 08:01:32 -0400 User-Agent: KMail/1.9.9 Cc: Jean Balthazar , caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904170801.35867.peng.zang@gmail.com> X-Spam: no; 0.00; hash:01 uncomment:01 escapes:01 val:01 peng:98 peng:98 2009:98 polymorphic:01 polymorphic:01 wrote:01 caml-list:01 int:01 accu:02 accu:02 define:02 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 See previous answers to this question: http://groups.google.com/group/fa.caml/browse_thread/thread/9bb6ff19373371fb I've used the classical solution thus far and have not run into any trouble.. Peng On Friday 17 April 2009 05:37:52 am Jean Balthazar wrote: > Dear OCamlers, > > I try to define a polymorphic container encapsulating a list. I'd like to > define > a map and a fold method. I have read in the documentation how > to specify a polymorphic fold method but I'm unable to transpose > for the map method. I include in the code below a tentative: the map1 > method is not polymorphic. If I uncomment the map2 method, I have the error > > This type scheme cannot quantify 'c : > it escapes this scope. > > Do you have any idea how to solve this problem? And aditionnaly, could you > explain > me why it works for fold and not for map? > > All the best, > Jean > > *************************************************************************** >*************************** > > class ['elt] container arg = > object > > val _repr = arg > > method fold : 'b. ('b -> 'elt -> 'b) -> 'b -> 'b > = fun f accu -> List.fold_left f accu _repr > > method map1 f = {< _repr = List.map f _repr >} > > (* > method map2 : 'c.('elt -> 'c) -> ('c container) > = function f -> new container (List.map f _repr) > *) > end > > > let l = new container [1;2;3] > > let fint = l#fold (fun acc x -> x + acc) 0 > and fstring = l#fold (fun acc x -> (string_of_int x)^acc) "empty" > > > let mint = l#map1 (function x -> 0) > let mstring = l#map1 (function x -> "zero") -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD4DBQFJ6G+ffIRcEFL/JewRAmmdAKCYZabKzST8EgFhirfKumt0AwbP5ACYq4Qf BIX7A9TN5v4zce0seJbMEA== =mhdV -----END PGP SIGNATURE-----