caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Polux Moon <polux.moon@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Problem with forall and method
Date: Tue, 26 Jul 2011 14:17:58 +0200	[thread overview]
Message-ID: <CANGFCiDQJPEAuWFo8MgQYQuOapUE_FMRsPCq8kR+scikeRJsBQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 726 bytes --]

(Sorry for duplicate mail, I forgot to change the subject in the first one)

Hi,

I have a type error on code similar to :

-----
type 'par t = 'par

let ident v = v

class alias =
object
  method alias : 'a . 'a t -> 'a = ident (* type error here *)
end
-----

Which gives :

-----
Error: This expression has type 'a. 'a t -> 'a
       but an expression was expected of type 'b. 'b t -> 'b
       Type 'a a = 'a is not compatible with type 'b t = 'b
-----

The problem is related to unification of foralls containing named type in a
method.
The compiler accepts equivalent code when not using the named type "t" or
when not using a method (see attached file).

Is it a [known] limitation ? Is there a way to work around it ?

[-- Attachment #1.2: Type: text/html, Size: 943 bytes --]

[-- Attachment #2: forallclass.ml --]
[-- Type: text/x-ocaml, Size: 300 bytes --]

type 'par t = 'par

let ident v = v (* here adding : 'a . 'a a -> 'a changes nothing *)

class alias =
object
  method alias : 'a . 'a t -> 'a = ident (* NOT OK *)
end

(* but *)
let alias : 'a . 'a t -> 'a = ident (* OK *)
type r = { alias : 'a . 'a t -> 'a}
let alias = { alias = ident } (* OK *)


             reply	other threads:[~2011-07-26 12:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26 12:17 Polux Moon [this message]
2011-07-26 22:46 ` 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=CANGFCiDQJPEAuWFo8MgQYQuOapUE_FMRsPCq8kR+scikeRJsBQ@mail.gmail.com \
    --to=polux.moon@gmail.com \
    --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).