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 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 44BBDBC6B for ; Fri, 9 Nov 2007 02:36:12 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMdIM0fAXQImh2dsb2JhbACPAQEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,392,1188770400"; d="scan'208";a="4049436" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Nov 2007 02:36:11 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA91aB0d016981 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 9 Nov 2007 02:36:11 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAMdIM0dIDsqxXWdsb2JhbACOdxQFKAQ X-IronPort-AV: E=Sophos;i="4.21,392,1188770400"; d="scan'208";a="5605400" Received: from ro-out-1112.google.com ([72.14.202.177]) by mail3-smtp-sop.national.inria.fr with ESMTP; 09 Nov 2007 02:36:10 +0100 Received: by ro-out-1112.google.com with SMTP id m6so2705539roe for ; Thu, 08 Nov 2007 17:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:reply-to:to:subject:date:user-agent:references:in-reply-to:content-type:content-transfer-encoding:content-disposition:message-id; bh=4bf7Mpst4A9iuwqLUzRb79mbHUJ5Iw5eMvDTLKO4xtw=; b=jvHDYdp8dQk5zcX7YcTfDQFMLwE0dAwIk4XohTk5GJDDGKzia2DZxCndynH1+G+6hzVVyX9HcW5ZsbWx/pY46Gu/zNeKVAO6OwR3uWDXORXEkd618JiUUuE4e/KDF780YKfEJMv2cNS4bcBosV9hYRv3WdSJt1bI3AMN0hNSt6c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:reply-to:to:subject:date:user-agent:references:in-reply-to:content-type:content-transfer-encoding:content-disposition:message-id; b=WnrJG5tKNWyGcsvnOelQBqht/0+pGSOTXKefz7CbgFLrUocvf98lhyqQf2ghe2toyqJeXIRWI8un7hS/kMzYPIm/XFtaN3CVUlCRGeytXb7AAVwgKBUSUxLpZo/MJigrkwqsDlssfOq26g3X30aGUWAG1akcPqjYLgSiIAn/5d4= Received: by 10.100.41.16 with SMTP id o16mr2139074ano.1194572169309; Thu, 08 Nov 2007 17:36:09 -0800 (PST) Received: from tama-chan ( [24.98.134.200]) by mx.google.com with ESMTPS id 27sm1620534wra.2007.11.08.17.36.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Nov 2007 17:36:08 -0800 (PST) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@inria.fr Subject: Re: [Caml-list] a function for polymorphic and monomorphic objects Date: Thu, 8 Nov 2007 20:35:57 -0500 User-Agent: KMail/1.9.7 References: <20071108.180532.68538077.keiko@kurims.kyoto-u.ac.jp> <4732E97B.9080805@fmf.uni-lj.si> <20071108.210939.68538729.keiko@kurims.kyoto-u.ac.jp> In-Reply-To: <20071108.210939.68538729.keiko@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200711082036.07469.peng.zang@gmail.com> X-Miltered: at discorde with ID 4733B98B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 sigs:01 foo:01 val:01 foo:01 quantified:01 val:01 annotations:01 beginner's:01 ocaml:01 bug:01 peng:98 peng:98 protects:98 unbound:01 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 So my take is that since o2 is a completely different beast, ie. monomorphic, it really is of a different type. And should not be confused with polymorphic cousins. Functions that take them as an argument will fundamentally have different types. Eg. one monomorphic, the other poly. You want this distinction normally as it protects you from running o2 on a (int -> int) and later run it on a (int -> string). However I can see how especially when the monomorphic version is still "unbound", ie. still _'a, one might want to write one function to deal with both. I don't know of a nice way to do this as the type sigs are fundamentally different. That said, one can always resort to black magic when the type system gets in the way assuming you know what you're doing: # let foo arg = (arg: 'a) -> 'a list; ..>)#map string_of_int;; val foo : < map : 'a. (int -> 'a) -> 'a list; .. > -> string list = # foo o1;; - - : string list = ["1"; "2"; "3"] # foo (Obj.magic o2);; - - : string list = ["1"; "2"; "3"] Peng On Thursday 08 November 2007 07:09:39 am Keiko Nakata wrote: > > In your case you got it wrong when you quantified 'a in the object p. > > > > # let p = object method map = fun f -> List.map f [1;2;3] end;; > > val p : < map : (int -> 'a) -> 'a list > = > > Perhaps I oversimplified my example. > Indeed I want to make p a function like > > let p1 l = object > method map : 'a.(int -> 'a) -> 'a list = fun f -> List.map f l > end;; > > let o1 = p1 [1;2;3];; > - val o1 : < map : 'a. (int -> 'a) -> 'a list > = > > Then I need type annotations > > let p2 l = object > method map = fun f -> List.map f l > end;; > let o2 = p2 [1;2;3];; > - val o2 : < map : (int -> '_a) -> '_a list > = > > > With best, > keiko > > _______________________________________________ > 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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFHM7mHfIRcEFL/JewRAvCYAKCBDF0GoWWpeQTRtb/0ZTNWlCTBXgCg0HO/ VYPxEIQU88Fmctql0Cw910U= =fcz+ -----END PGP SIGNATURE-----