Version française
Home     About     Download     Resources     Contact us    
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 
situation:

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?

Chris

-------------------
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