caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: nadji@noos.fr
To: caml-list@inria.fr
Subject: [Caml-list] polymorphic method question
Date: Wed, 21 Aug 2002 23:49:38 +0200	[thread overview]
Message-ID: <3D640AF1.C24688A@noos.fr> (raw)

Hi,

I am puzzled by this behaviour, can a guru explain me ?
I have two classes
class type ['a] basic = object
  method foo : 'a
end;;

 class ['a] toto (a:'a) = object
  method foo = a
  method bar = ()
end;;

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 );;

class gentoto =
object
  method gen : 'a . 'a -> 'a basic =
(*     fun x -> (new toto x :> 'a basic ) *)
    newtotoasbasic
end;;

The compiler agrees with me ...
What is wrong with the first declaration ?

Thanks,
Nadji

-------------------
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 21:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-21 21:49 nadji [this message]
2002-08-21 22:57 ` Jacques Garrigue
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=3D640AF1.C24688A@noos.fr \
    --to=nadji@noos.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).