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=DNS_FROM_RFC_POST, HTML_MESSAGE,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 A50D4BBC4 for ; Fri, 17 Apr 2009 11:37:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlACAF/q50lKfU4akGdsb2JhbACCIDGTPD8BAQEBCQkMBxEDpzuBCZAVAQMBA4N6Bg X-IronPort-AV: E=Sophos;i="4.40,203,1238968800"; d="scan'208";a="24737027" Received: from ey-out-2122.google.com ([74.125.78.26]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Apr 2009 11:37:53 +0200 Received: by ey-out-2122.google.com with SMTP id 9so160625eyd.33 for ; Fri, 17 Apr 2009 02:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=ozln+NAi3NAp/NWEfRL6OUDXD8bJ/+jMr5Gl3tYPJ6w=; b=o2li5dAz9Y+uxs22tgsR0E6ltBbWn90d4ThC3R05TeFgslaGDeR9Ih3s4NC4tEB9/7 W5haj4pE1gW4Hi/76c66cXQL9i2Oo+m6IqXqXmfDZ35EgRwnWn6urODvKnNe/oE3OoWZ qxd6M9gR6IwpCi9sxpSaiKOeGcZi31nzJw4gg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Aqlw9WxAinPJYMlw4NkIqsR/aTDokSKSRY7F0CvA3ccT0QYoJ3G9bwYcOBe2p4k04f VgclPjOMktjdDgrqRchl+4r3k/7ogVFytYpqKMqxF4dlctlwbRMB3g/QTvto7D81iofb ESGXQnfzmJlw40agJejv4/F65HS/9pcyOyWzE= MIME-Version: 1.0 Received: by 10.216.49.194 with SMTP id x44mr477294web.130.1239961072440; Fri, 17 Apr 2009 02:37:52 -0700 (PDT) Date: Fri, 17 Apr 2009 11:37:52 +0200 Message-ID: Subject: Unable to define a polymorphic map method From: Jean Balthazar To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016367f9b144217d80467bcef34 X-Spam: no; 0.00; uncomment:01 escapes:01 val:01 uncomment:01 escapes:01 val:01 polymorphic:01 polymorphic:01 int:01 int:01 accu:02 accu:02 define:02 define:02 string:02 --0016367f9b144217d80467bcef34 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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") --0016367f9b144217d80467bcef34 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Dear OCamlers,

I try to define a polymorphic container=A0 encapsulat= ing 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 metho= d
is not polymorphic. If I uncomment the map2 method, I have the error
This type scheme cannot quantify &#= 39;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,<= br> Jean

***************************************************************= ***************************************

class ['elt] container a= rg =3D
object

=A0 val=A0 _repr =3D arg

=A0 method fold : &= #39;b. ('b -> 'elt -> 'b) -> 'b -> 'b
=A0=A0=A0 =3D fun f accu -> List.fold_left f accu _repr

=A0 metho= d map1 f =3D {< _repr =3D List.map f _repr >}

(*
=A0 method= map2 : 'c.('elt -> 'c) -> ('c container)
=A0=A0= =A0 =3D function f -> new container (List.map f _repr)
*)
end
=A0=A0=A0

let l =3D new container [1;2;3]

let f= int =3D l#fold (fun acc x -> x + acc) 0
and fstring =3D l#fold (fun a= cc x -> (string_of_int x)^acc) "empty"


let mint =3D= l#map1 (function x -> 0)
let mstring =3D l#map1 (function x -> "zero")
--0016367f9b144217d80467bcef34--