Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Type inference + optional parameters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christoph Bauer <c_bauer@i...>
Subject: [Caml-list] Type inference + optional parameters
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 = <fun>

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 = <fun>
# 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 = <fun>

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