[
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: | Jacques GARRIGUE <garrigue@k...> |
| Subject: | Re: [Caml-list] Re: Type unification problem |
From: Richard Jones <rich@annexia.org> > > Why this error (below)? I can "fix" it by adding quite a lot of > > explicit types (I need one on every function which uses the > > Dbi.connection parameter). Is there a simpler way to fix it? If I look at the details of this error, I can see: map : ([> `String of 'c ] list -> 'c) -> string list; in the first type, and map : 'g. (Dbi.sql_t list -> 'g) -> 'g list; in the Dbi.statement part of the second type. These two types are incompatible: a polymorphic method type can only be unified with a method with the same polymorphism. Before calling a polymorphic method, you must make sure that its type is known to the compiler, otherwise you get the above kind of errors. The local solution is to annotate every polymorphic method call with the type of the object: (stm : Dbi.statement)#map ... But the system is more clever than that: you can simply annotate all parameters which may eventually yield a Dbi.statement, whenever this Dbi.statement is used for a polymorphic method call. This is probably why you found that annotating all Dbi.connection parameters worked. But you don't need to annotate all of them, just the ones where there is a polymorphic method call in the body. Note also that you can annotate with #Dbi.connection, to allow subclasses. (Actually, annotating all of them may be a good idea. Olabl had a warning had warning when calling a method on an object of unknown type.) Jacques Garrigue ------------------- 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