[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Romain Beauxis <toots@r...> |
| Subject: | bug in object type inference ? |
Hi all ! While preparing a function that takes an object as parameter, I encountered a type issue on which I'd like to have some feedback.. Let's consider this very simple example: * We got a class of objects: class test = object(self) method test ?(foo="bar") () = () end * We instanciate one of them: let p = new test * We define a function that takes one of them, plus additional argument, and apply to the method test: let f = fun p foo -> p#test ~foo () * Then, we got a type error: This expression has type test but is here used with type < test : foo:'a -> unit -> 'b; .. > Types for method test are incompatible This means that the optional argument for method test in class test is infered as mandatory argument for the object passed to f. Or course, this can be solved by writing directly: let f : test -> string -> unit = fun p foo -> p#test ~foo () But I'm wondering why the type inference could not just say "either optional either mandatory argument". After all, this confusion comes from the fact the the semantic for applying optional and mandatory arguments are the same... Or perhaps this is a well known subject and I'm not documented enough ? Romain