Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] optional arguments and unification
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Hecker <checker@d...>
Subject: [Caml-list] optional arguments and unification

I'm not sure I'm using the term "unification" properly, but here's the 

let f ?opt x = x + 1
let g x = x + 1
let h = if true then f else g

This expression has type int -> int but is here used with type
   ?opt:'a -> int -> int

So you have to do this:

let h = if true then f ?opt:None else g

Which is kinda ugly and goes against the "spirit" of optional arguments, I 
think.  Would it be possible to have a rule that says "if two types need to 
be unified and the only thing standing in the way are unspecified optional 
arguments then the compiler will default them automatically"?  Or does that 
lead to something unsound?


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: