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 TAA02724; Tue, 2 Sep 2003 19:06:55 +0200 (MET DST) 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 TAA32216 for ; Tue, 2 Sep 2003 19:06:54 +0200 (MET DST) Received: from mail.speakeasy.net (mail9.speakeasy.net [216.254.0.209]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h82H6rT08115 for ; Tue, 2 Sep 2003 19:06:53 +0200 (MET DST) Received: (qmail 26009 invoked from network); 2 Sep 2003 17:06:52 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail9.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 2 Sep 2003 17:06:52 -0000 Date: Tue, 2 Sep 2003 10:06:51 -0700 (PDT) From: brogoff@speakeasy.net To: Christoph Bauer cc: OCaml List Subject: Re: [Caml-list] Type inference + optional parameters In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 inference:01 val:01 val:01 bauer:01 ocamls:01 inference:01 3.07:01 bauer:01 foreach:01 expr:01 bug:01 faq:01 faq:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This behavior doesn't seem strange to me, not compared to that function you want to define, but what the heck, here's one solution to get the type you want # let do_with_opt_conv ?(conv = Obj.magic) a = conv a;; val do_with_opt_conv : ?conv:('a -> 'b) -> 'a -> 'b = and here's a better one # let do_with_opt_conv ?(conv = fun x -> invalid_arg "do_with_opt_conv") a = conv a;; val do_with_opt_conv : ?conv:('a -> 'b) -> 'a -> 'b = -- Brian On Tue, 2 Sep 2003, Christoph Bauer wrote: > Hi, > > ocamls type inference uses information of optionl arguments. This > results in a strange behaviour. Here is an example: > > Objective Caml version 3.07+beta 2 > > # let do_with_conv ~conv a = conv a;; > do_with_conv ~conv:int_of_string "1" ;; > val do_with_conv : conv:('a -> 'b) -> 'a -> 'b = > > This is ok. > > # let do_with_opt_conv ?(conv = fun s -> s) a = conv a;; > do_with_opt_conv ~conv:string_of_int "1";;- : int = 1 > # val do_with_opt_conv : ?conv:('a -> 'a) -> 'a -> 'a = > # do_with_opt_conv ~conv:string_of_int "1";; > > Is there a solution? It is not possible to > add the "right" type information: > > # let do_with_opt_conv ?(conv : 'a -> 'b = fun s -> s) (a:'a) : 'b = conv a;; > val do_with_opt_conv : ?conv:('a -> 'a) -> 'a -> 'a = > > Thanks, > Christoph Bauer > > -- > proc self {} {foreach c [split [info body self] ""] d {14 -7 0 0 4 -67 4 73 11 > 69 24 -83 -15 6 -4 -84 78 20 11 -78 -1 -1 79 19 -8 4} { binary scan $c c c > if {[catch {append r [format %c [expr $c+$d]]}]} {return $r};}};puts [self] > > ------------------- > 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 > ------------------- 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