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 CAA26138; Fri, 16 Feb 2001 02:54:27 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA26125 for ; Fri, 16 Feb 2001 02:54:26 +0100 (MET) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f1G1sPj03450 for ; Fri, 16 Feb 2001 02:54:25 +0100 (MET) Received: from localhost (patrick@localhost) by fledge.watson.org (8.11.1/8.11.1) with SMTP id f1G1sO449818 for ; Thu, 15 Feb 2001 20:54:24 -0500 (EST) (envelope-from patrick@watson.org) Date: Thu, 15 Feb 2001 20:54:24 -0500 (EST) From: Patrick M Doane To: caml-list@inria.fr Subject: [Caml-list] Typing of default arguments Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I am having difficulty understanding the typing rules for default arguments. Here are some test cases: (* No default arguments: all of these work *) let f ~g x = g x let a = f (fun x -> x) () let b = f (fun x -> (x,x)) () let c = f ~g:(fun x -> x) () let d = f ~g:(fun x -> (x,x)) () (* Default argument: last one fails to type-check *) let f' ?(g = (fun x -> x)) x = g x let a' = f' (fun x -> x) () let b' = f' (fun x -> (x,x)) () let c' = f' ~g:(fun x -> x) () let d' = f' ~g:(fun x -> (x,x)) () If I remove the offending case at the end, I notice that the difference between f and f' is: val f : g:('a -> 'b) -> 'a -> 'b val f' : ?g:('a -> 'a) -> 'a -> 'a So why does the definition for b' typecheck properly? The type of the first argument is not 'a -> 'a but rather 'a -> 'a * 'a. It's unfortunate that supplying a default argument restricts the polymorphism and reuse of the function. I would like someway to provide the default without losing that polymorphic capability. I think this example shows that is should at least be legal to do (from the declaration of b'). Any ideas? Thanks, Patrick Doane ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr