caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ivan <ivg@ieee.org>
To: Alain Frisch <alain@frisch.fr>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] type inference with classes
Date: Fri, 3 Aug 2012 09:15:26 +0400	[thread overview]
Message-ID: <CAL9dnAEosWx_wwAhKW23h3bWZ45JFHsBJVq51MZ1_pxOmbRQiQ@mail.gmail.com> (raw)
In-Reply-To: <501B588B.6040006@frisch.fr>

[-- Attachment #1: Type: text/plain, Size: 1726 bytes --]

On 3 August 2012 08:50, Alain Frisch <alain@frisch.fr> wrote:

> Hello,
>
> I don't know if this covers all the case, but you need to keep in mind the
> following points.  Feel free to add to the list.
>

Thanks for nice and structured answer!

I'll try to expand it with my cases, but due to lack of comprehension they
will not be so clear =)

So the setup is follows: I have a class with a type explicitly specified in
mli file. No inference on it's methods. And a function, that takes some
object and type system tries to infer what objects it can accept.

Starting from a  simple case:

let reset_env_model state v =
  let q = Queue.create () in
  Queue.iter (fun p -> v#expand_row p) q

produces an error:
    This expression has type GTree.view
       but an expression was expected of type < expand_row : 'a -> unit; ..
>
       Types for method expand_row are incompatible

because expand_row method of type GTree.view has type:
   expand_row : Gtk.tree_path -> unit;

I think, that compiler have a reason to refuse this code: function wants a
method, that can take an arbitrary value of type 'a, but I pass a method
that has a covariant type Gtk.tree_path in position left to arrow. So he
complains correctly. I agree =) I think that this case has
some correspondence with your  case #1.

But, why in the following code:

let reset_env_model state v =
  let q = Queue.create () in
  let m,_,_ = State.env_model state in
  m#foreach (fun p _ -> if v#row_expanded p then Queue.push p q; false);
  set_env_model state v;
  Queue.iter (fun p -> v#expand_row p) q

compiler cannot infer, that object p has type Gtk.tree_path, and with this
proposition imply, that the expand_row method has a type "Gtk.tree_path ->
unit"?

[-- Attachment #2: Type: text/html, Size: 2578 bytes --]

  reply	other threads:[~2012-08-03  5:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03  4:23 Ivan
2012-08-03  4:50 ` Alain Frisch
2012-08-03  5:15   ` Ivan [this message]
2012-08-03  5:32     ` Jacques Garrigue
2012-08-03  6:09       ` Ivan
2012-08-03 23:14 Jacques Garrigue

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=CAL9dnAEosWx_wwAhKW23h3bWZ45JFHsBJVq51MZ1_pxOmbRQiQ@mail.gmail.com \
    --to=ivg@ieee.org \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    /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).