caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: rich@annexia.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Re: Type unification problem
Date: Thu, 01 Jul 2004 11:38:44 +0900 (JST)	[thread overview]
Message-ID: <20040701.113844.07258828.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20040630122116.GA8170@redhat.com>

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


      reply	other threads:[~2004-07-01  2:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-30 12:16 [Caml-list] " Richard Jones
2004-06-30 12:21 ` [Caml-list] " Richard Jones
2004-07-01  2:38   ` Jacques GARRIGUE [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040701.113844.07258828.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).