caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: nadji@noos.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic method question
Date: Thu, 22 Aug 2002 07:57:44 +0900	[thread overview]
Message-ID: <20020822075744N.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3D640AF1.C24688A@noos.fr>

From: nadji@noos.fr
> I am puzzled by this behaviour, can a guru explain me ?
> I have two classes
[...]
> I want to do a class gentoto :
> class gentoto = object
>   method gen : 'a . 'a -> 'a basic =
>     fun x -> (new toto x :> 'a basic )
> end;;
> But the compiler complains that :
>       Characters 64-98:
>       fun x -> (new toto x :> 'a basic )
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This method has type 'a -> 'a basic which is less general than
>   'b. 'b -> 'b basic
> 
> ... but if I do :
> let newtotoasbasic x = (new toto x :> 'a basic );;
[...]
> The compiler agrees with me ...
> What is wrong with the first declaration ?

There is a problem with the scoping of named type variables in the
language, which makes them incompatible with polymorphic methods.
You can solve this by using anonymous variables:
# class gentoto = object
    method gen : 'a . 'a -> 'a basic =
      fun x -> (new toto x :> _ basic)
  end;;
class gentoto : object method gen : 'a -> 'a basic end

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:[~2002-08-21 22:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-21 21:49 nadji
2002-08-21 22:57 ` Jacques Garrigue [this message]
2006-07-10 19:21 Polymorphic " brogoff
2006-07-10 20:05 ` [Caml-list] " Richard Jones
2006-07-10 23:25   ` brogoff
2006-07-11  2:24     ` skaller
2006-07-11  4:56       ` brogoff
2006-07-11  2:09 ` Jacques Garrigue
2006-07-11  5:22   ` brogoff
2006-07-11  7:32     ` Jacques Garrigue
2006-07-11 18:20       ` brogoff
2006-07-12  0:37         ` Jacques Garrigue
2006-07-12 19:26           ` brogoff

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=20020822075744N.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=nadji@noos.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).