* [Caml-list] Type unification problem
@ 2004-06-30 12:16 Richard Jones
2004-06-30 12:21 ` [Caml-list] " Richard Jones
0 siblings, 1 reply; 3+ messages in thread
From: Richard Jones @ 2004-06-30 12:16 UTC (permalink / raw)
To: caml-list
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?
Rich.
File "contact.ml", line 81, characters 25-28:
This expression has type
Apache.Request.t ->
Cgi.cgi ->
(< prepare_cached : string ->
(< execute : ([> `Int of string ] as 'c) list -> 'd;
map : ([> `String of 'e ] list -> 'e) -> string list;
.. >
as 'b);
.. >
as 'a) ->
string -> string -> 'f -> unit
but is here used with type
Apache.Request.t ->
Cgi.cgi -> Dbi.connection -> int -> string -> Ewp.login_t -> unit
Type 'a is not compatible with type
Dbi.connection =
< close : unit -> unit; closed : bool; commit : unit -> unit;
database : string; database_type : string; debug : bool;
ex : string -> Dbi.sql_t list -> Dbi.statement; host : string option;
id : int; password : string option; ping : unit -> bool;
port : string option; prepare : string -> Dbi.statement;
prepare_cached : string -> Dbi.statement;
register_postrollback : (unit -> unit) -> Dbi.postrollback_handle;
register_precommit : (unit -> unit) -> Dbi.precommit_handle;
rollback : unit -> unit; set_debug : bool -> unit;
unregister_postrollback : Dbi.postrollback_handle -> unit;
unregister_precommit : Dbi.precommit_handle -> unit;
user : string option >
Type 'b is not compatible with type
Dbi.statement =
< connection : Dbi.connection; execute : Dbi.sql_t list -> unit;
fetch1 : unit -> Dbi.sql_t list;
fetch1hash : unit -> (string * Dbi.sql_t) list;
fetch1int : unit -> int; fetch1string : unit -> string;
fetchall : unit -> Dbi.sql_t list list; finish : unit -> unit;
fold_left : 'g. ('g -> Dbi.sql_t list -> 'g) -> 'g -> 'g;
fold_right : 'h. (Dbi.sql_t list -> 'h -> 'h) -> 'h -> 'h;
iter : (Dbi.sql_t list -> unit) -> unit;
map : 'i. (Dbi.sql_t list -> 'i) -> 'i list; names : string list;
serial : string -> int >
Type 'c is not compatible with type
Dbi.sql_t =
[ `Binary of string
| `Bool of bool
| `Date of Dbi.date
| `Decimal of Dbi.Decimal.t
| `Float of float
| `Int of int
| `Interval of Dbi.datetime
| `Null
| `String of string
| `Time of Dbi.time
| `Timestamp of Dbi.datetime
| `Unknown of string ]
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
If I have not seen as far as others, it is because I have been
standing in the footprints of giants. -- from Usenet
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Caml-list] Re: Type unification problem
2004-06-30 12:16 [Caml-list] Type unification problem Richard Jones
@ 2004-06-30 12:21 ` Richard Jones
2004-07-01 2:38 ` Jacques GARRIGUE
0 siblings, 1 reply; 3+ messages in thread
From: Richard Jones @ 2004-06-30 12:21 UTC (permalink / raw)
To: caml-list
On Wed, Jun 30, 2004 at 01:16:25PM +0100, rich wrote:
> 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?
[Sorry, there was an actual error in the last posting. This is the
real error:]
File "contact.ml", line 81, characters 25-28:
This expression has type
Apache.Request.t ->
Cgi.cgi ->
(< prepare_cached : string ->
(< execute : Dbi.sql_t list -> unit;
map : ([> `String of 'c ] list -> 'c) -> string list;
.. >
as 'b);
.. >
as 'a) ->
int -> string -> 'd -> unit
but is here used with type
Apache.Request.t ->
Cgi.cgi -> Dbi.connection -> int -> string -> Ewp.login_t -> unit
Type 'a is not compatible with type
Dbi.connection =
< close : unit -> unit; closed : bool; commit : unit -> unit;
database : string; database_type : string; debug : bool;
ex : string -> Dbi.sql_t list -> Dbi.statement; host : string option;
id : int; password : string option; ping : unit -> bool;
port : string option; prepare : string -> Dbi.statement;
prepare_cached : string -> Dbi.statement;
register_postrollback : (unit -> unit) -> Dbi.postrollback_handle;
register_precommit : (unit -> unit) -> Dbi.precommit_handle;
rollback : unit -> unit; set_debug : bool -> unit;
unregister_postrollback : Dbi.postrollback_handle -> unit;
unregister_precommit : Dbi.precommit_handle -> unit;
user : string option >
Type 'b is not compatible with type
Dbi.statement =
< connection : Dbi.connection; execute : Dbi.sql_t list -> unit;
fetch1 : unit -> Dbi.sql_t list;
fetch1hash : unit -> (string * Dbi.sql_t) list;
fetch1int : unit -> int; fetch1string : unit -> string;
fetchall : unit -> Dbi.sql_t list list; finish : unit -> unit;
fold_left : 'e. ('e -> Dbi.sql_t list -> 'e) -> 'e -> 'e;
fold_right : 'f. (Dbi.sql_t list -> 'f -> 'f) -> 'f -> 'f;
iter : (Dbi.sql_t list -> unit) -> unit;
map : 'g. (Dbi.sql_t list -> 'g) -> 'g list; names : string list;
serial : string -> int >
make: *** [contact.cmo] Error 2
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Learning Objective CAML for C, C++, Perl and Java programmers:
http://www.merjis.com/richj/computers/ocaml/tutorial/
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Re: Type unification problem
2004-06-30 12:21 ` [Caml-list] " Richard Jones
@ 2004-07-01 2:38 ` Jacques GARRIGUE
0 siblings, 0 replies; 3+ messages in thread
From: Jacques GARRIGUE @ 2004-07-01 2:38 UTC (permalink / raw)
To: rich; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-07-01 2:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-30 12:16 [Caml-list] Type unification problem Richard Jones
2004-06-30 12:21 ` [Caml-list] " Richard Jones
2004-07-01 2:38 ` Jacques GARRIGUE
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox