From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA01212; Sun, 24 Feb 2002 15:01:31 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA01512 for ; Sun, 24 Feb 2002 15:01:30 +0100 (MET) Received: from mail.cs.net.pl (cyber.cs.net.pl [62.233.142.98]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g1OE1Tv25556 for ; Sun, 24 Feb 2002 15:01:29 +0100 (MET) Received: by mail.cs.net.pl (Postfix, from userid 510) id 3C367823; Sun, 24 Feb 2002 15:01:25 +0100 (CET) Date: Sun, 24 Feb 2002 15:01:25 +0100 From: Tomasz Zielonka To: CAML list Subject: [Caml-list] Narrowing coercions for functions with optional parameters Message-ID: <20020224140125.GA26745@cs.net.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.27i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi I'm just curious - would it be possible to implement narrowing coercions for functions with optional parameters? It seems that such coercion is performed automatically in some situations. Example: # type basefun = int -> int ;; type basefun = int -> int # let f x = x ;; val f : 'a -> 'a = # (f :> basefun) ;; - : basefun = # let g ?(add = 0) x = x + add ;; val g : ?add:int -> int -> int = # (g :> basefun) ;; This expression cannot be coerced to type basefun = int -> int; it has type ?add:int -> int -> int but is here used with type int -> int (* Of course I can do: *) # (fun x -> g x : basefun) ;; - : basefun = (* Hmmm... now it gets strange... *) # let coerce f x = f x val coerce : ('a -> 'b) -> 'a -> 'b = # coerce g ;; - : int -> int = (* The above works, so g was used with type: int -> int *) (* But... *) # (g : int -> int) ;; This expression has type ?add:int -> int -> int but is here used with type int -> int (* ??? *) I hope someone can explain me this... best regards, tom -- .-. Tomasz Zielonka CYBER SERVICE oo| programista http://www.cs.net.pl /`'\ zielony@cs.net.pl (\_;/) tel: [48] (22) 723-06-79 | tel/fax: [48] (22) 723-01-75 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners