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=3.3 required=5.0 tests=AWL,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 12DC1BBC4 for ; Fri, 17 Apr 2009 14:49:07 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgcDABgY6EnRVduokWdsb2JhbACCITCTPD8BAQEBCQkMBw+nPIEJkBEBAwEDgXuBfwY X-IronPort-AV: E=Sophos;i="4.40,204,1238968800"; d="scan'208";a="24746838" Received: from mail-ew0-f168.google.com ([209.85.219.168]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Apr 2009 14:49:06 +0200 Received: by ewy12 with SMTP id 12so453165ewy.9 for ; Fri, 17 Apr 2009 05:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=Pi1JIjgPxzD02CSRD8+jrv82p9afY1/QYyxHxR0kQGY=; b=wO+eS/S3HNzscBKgN+v8INDfa2zram4EKfLgZwiQIdn5DRnD9y2Wqi4GWkGV0YVjmE V5+zQYnktOjW2xe0lSHiUFSLP3j3EW9ma4bwjD5w2fA3JbODCQRQnbuLVtpxyAeHCEmA tYk6zQCIRFHoy7FKV3OxnZPXvQEldH6uMxEZo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=EVqU+DCf89G/949IHvxvUllkMOjFt80eamKX+6BkpnPza1FHCftZWb8o8f2Dd0xlVv sZe68VrQfMgB1s+f0eiU5ZodFdN1dYEfRIlciC5+5qG9U+hagOfif4yiZ8IaaLAkXpr2 gnfmQfbWuKyKQas4Imfqahomxg6pUofN6E7ZI= MIME-Version: 1.0 Received: by 10.216.21.211 with SMTP id r61mr512282wer.211.1239972546139; Fri, 17 Apr 2009 05:49:06 -0700 (PDT) In-Reply-To: <200904170801.35867.peng.zang@gmail.com> References: <200904170801.35867.peng.zang@gmail.com> Date: Fri, 17 Apr 2009 14:49:06 +0200 Message-ID: Subject: Re: [Caml-list] Unable to define a polymorphic map method From: Jean Balthazar To: peng.zang@gmail.com Cc: caml-list@yquem.inria.fr, caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016364c7dd724d6d40467bf9ba8 X-Spam: no; 0.00; hash:01 uncomment:01 escapes:01 val:01 hash:01 uncomment:01 escapes:01 val:01 2009:98 peng:98 peng:98 2009:98 polymorphic:01 polymorphic:01 wrote:01 --0016364c7dd724d6d40467bf9ba8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thank your for your answer, but it does not solve my actual problem: suppose I have a data-structure with no cons (for example a matrix). I know how to implement a map function but I don't know how to type it as a method. Jean 2009/4/17 Peng Zang > -----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----- > --0016364c7dd724d6d40467bf9ba8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank your for your answer, but it does not solve my actual
problem: sup= pose I have a data-structure with no cons (for example
a matrix). I know= how to implement a map function but I don't know
how to type it as = a method.

Jean

2009/4/17 Peng Zang <peng.zang@gmail.com>= ;
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

See previous answers to this question:

http://groups.google.com/group/fa.caml/brow= se_thread/thread/9bb6ff19373371fb

I've used the classical solution thus far and have not run into any tro= uble..

Peng

On Friday 17 April 2009 05:37:52 am Jean Balthazar wrote:
> Dear OCamlers,
>
> I try to define a polymorphic container =A0encapsulating 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<= br> > 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 =3D
> object
>
> =A0 val =A0_repr =3D arg
>
> =A0 method fold : 'b. ('b -> 'elt -> 'b) -> &= #39;b -> 'b
> =A0 =A0 =3D fun f accu -> List.fold_left f accu _repr
>
> =A0 method map1 f =3D {< _repr =3D List.map f _repr >}
>
> (*
> =A0 method map2 : 'c.('elt -> 'c) -> ('c contain= er)
> =A0 =A0 =3D function f -> new container (List.map f _repr)
> *)
> end
>
>
> let l =3D new container [1;2;3]
>
> let fint =3D l#fold (fun acc x -> x + acc) 0
> and fstring =3D l#fold (fun acc x -> (string_of_int x)^acc) "e= mpty"
>
>
> let mint =3D l#map1 (function x -> 0)
> let mstring =3D l#map1 (function x -> "zero")
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD4DBQFJ6G+ffIRcEFL/JewRAmmdAKCYZabKzST8EgFhirfKumt0AwbP5ACYq4Qf
BIX7A9TN5v4zce0seJbMEA=3D=3D
=3DmhdV
-----END PGP SIGNATURE-----

--0016364c7dd724d6d40467bf9ba8--