* [Caml-list] confusing type error when using function with optional arguments
@ 2012-11-16 14:50 Milan Stanojević
2012-11-16 15:58 ` Török Edwin
0 siblings, 1 reply; 4+ messages in thread
From: Milan Stanojević @ 2012-11-16 14:50 UTC (permalink / raw)
To: Caml List
I was playing with %revapply primitive and ran into the following
compiler behavior that I don't understand.
external (|!) : 'a -> ('a -> 'b) -> 'b = "%revapply"
let foo1 ?x ?y () = () (* val foo1 : ?x:'a -> ?y:'b -> unit -> unit
*)
let foo2 ?x ?y z = z (* val foo2 : ?x:'a -> ?y:'b -> 'c -> 'c *)
let x = () |! foo1 (* compiles just fine *)
let y = () |! foo2 (* fails with
Error: This expression has type ?x:'a ->
?y:'b -> 'c -> 'c
but an expression was expected of type
unit -> 'd *)
I don't understand why foo1 is fine and foo2 isn't. I would have
thought that I can use foo2 wherever I can foo1 since it has a
strictly more general type.
Am I missing something obvious here?
%revapply is not important here I just wanted to include context. I
get the same behavior in 3.12.1 and 4.00.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] confusing type error when using function with optional arguments
2012-11-16 14:50 [Caml-list] confusing type error when using function with optional arguments Milan Stanojević
@ 2012-11-16 15:58 ` Török Edwin
2012-11-16 16:05 ` Milan Stanojević
0 siblings, 1 reply; 4+ messages in thread
From: Török Edwin @ 2012-11-16 15:58 UTC (permalink / raw)
To: caml-list
On 11/16/2012 04:50 PM, Milan Stanojević wrote:
> I was playing with %revapply primitive and ran into the following
> compiler behavior that I don't understand.
>
> external (|!) : 'a -> ('a -> 'b) -> 'b = "%revapply"
>
> let foo1 ?x ?y () = () (* val foo1 : ?x:'a -> ?y:'b -> unit -> unit
> *)
> let foo2 ?x ?y z = z (* val foo2 : ?x:'a -> ?y:'b -> 'c -> 'c *)
>
> let x = () |! foo1 (* compiles just fine *)
>
> let y = () |! foo2 (* fails with
> Error: This expression has type ?x:'a ->
> ?y:'b -> 'c -> 'c
> but an expression was expected of type
> unit -> 'd *)
>
> I don't understand why foo1 is fine and foo2 isn't. I would have
> thought that I can use foo2 wherever I can foo1 since it has a
> strictly more general type.
> Am I missing something obvious here?
Its probably due to the optional labels, this works:
let y = () |! foo2 ?x:None ?y:None
--Edwin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] confusing type error when using function with optional arguments
2012-11-16 15:58 ` Török Edwin
@ 2012-11-16 16:05 ` Milan Stanojević
2012-11-16 16:10 ` Didier Cassirame
0 siblings, 1 reply; 4+ messages in thread
From: Milan Stanojević @ 2012-11-16 16:05 UTC (permalink / raw)
To: Török Edwin; +Cc: caml-list
>> I don't understand why foo1 is fine and foo2 isn't. I would have
>> thought that I can use foo2 wherever I can foo1 since it has a
>> strictly more general type.
>> Am I missing something obvious here?
>
> Its probably due to the optional labels, this works:
> let y = () |! foo2 ?x:None ?y:None
The question is why foo1 doesn't need this and foo2 does.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-16 16:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-16 14:50 [Caml-list] confusing type error when using function with optional arguments Milan Stanojević
2012-11-16 15:58 ` Török Edwin
2012-11-16 16:05 ` Milan Stanojević
2012-11-16 16:10 ` Didier Cassirame
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox