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.0 required=5.0 tests=none 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 EEAD8BC6B for ; Thu, 8 Nov 2007 11:44:28 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAAx3MkfAXQImh2dsb2JhbACOfwEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,388,1188770400"; d="scan'208";a="4024320" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Nov 2007 11:44:28 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lA8AiN9K014895 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 8 Nov 2007 11:44:28 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAJJ3MkfBAkMt/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.21,388,1188770400"; d="scan'208";a="19066132" Received: from vega.fmf.uni-lj.si (HELO postar.fmf.uni-lj.si) ([193.2.67.45]) by mail4-smtp-sop.national.inria.fr with ESMTP; 08 Nov 2007 11:44:28 +0100 Received: from localhost (unknown [192.168.5.1]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id 5F1421CCEA4; Thu, 8 Nov 2007 11:44:27 +0100 (CET) X-Virus-Scanned: amavisd-new at spam.fmf.uni-lj.si Received: from postar.fmf.uni-lj.si ([192.168.5.5]) by localhost (spam.fmf.uni-lj.si [192.168.5.1]) (amavisd-new, port 10024) with ESMTP id fuufE6NG57oe; Thu, 8 Nov 2007 11:44:24 +0100 (CET) Received: from [193.2.67.88] (unknown [193.2.67.88]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id B2F4E1CBE0F; Thu, 8 Nov 2007 11:44:24 +0100 (CET) Message-ID: <4732E97B.9080805@fmf.uni-lj.si> Date: Thu, 08 Nov 2007 11:48:27 +0100 From: Andrej Bauer Reply-To: Andrej.Bauer@andrej.com User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: Keiko Nakata , Caml Subject: Re: [Caml-list] a function for polymorphic and monomorphic objects References: <20071108.180532.68538077.keiko@kurims.kyoto-u.ac.jp> In-Reply-To: <20071108.180532.68538077.keiko@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 4732E887.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrej:01 andrej:01 annotations:01 quantified:01 val:01 val:01 annotations:01 polymorphic:01 polymorphic:01 wrote:01 caml-list:01 monomorphic:01 int:01 int:01 define:02 Keiko Nakata wrote: > Can I define a function taking as argument > an object with a method, say, "map" whose type is instantiatable to > (int -> int) -> int list? Don't write too many type annotations by hand and everything will be fine. In your case you got it wrong when you quantified 'a in the object p. Objective Caml version 3.09.3 # let p = object method map = fun f -> List.map f [1;2;3] end;; val p : < map : (int -> 'a) -> 'a list > = # let q = object method map = fun (f : int -> int) -> List.map f [1;2;3] end;; val q : < map : (int -> int) -> int list > = # let double o = o#map (fun x -> x*2);; val double : < map : (int -> int) -> 'a; .. > -> 'a = # double p;; - : int list = [2; 4; 6] # double q;; - : int list = [2; 4; 6] I think the general hint is this: first try without type annotations. Then, if you're not happy (say because the function is "too polymorphic") add as few type annotations as possible, e.g., annotate f above rather than map. Best regards, Andrej