caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Cannasse" <warplayer@free.fr>
To: "Lex Stein" <stein@eecs.harvard.edu>, <caml-list@inria.fr>
Subject: Re: [Caml-list] polymorphic methods in objects?
Date: Wed, 4 Jun 2003 12:31:11 +0900	[thread overview]
Message-ID: <002301c32a49$bef062b0$2413f9ca@WARP> (raw)
In-Reply-To: <Pine.BSF.4.51.0306032259480.25909@bowser.eecs.harvard.edu>

> Why can't objects have polymorphic methods ? I'm trying a compile and
> ocamlc gets upset because I have a method with an unbound type in its
> signature (see below for ocamlc error output).
>
> Must methods be type paramaterized through some kind of a template
> mechanism? This seems a bit limiting: the methods of an object would have
> their type signature fixed across the lifetime of an object.
>
>       method dummy_init : 'a -> unit
>       method dump : out_channel -> unit
>       method init : unit -> unit
>       method join : string -> unit
>       method null : unit -> unit
>       method resolv : string -> hmap option
>     end
> The method dummy_init has type 'a -> unit where 'a is unbound

two ways of doing that :

first, having a parameterized object :

class ['a] my_object : object
    method dummy_init : 'a -> unit
end

But perhaps here you really want that any value passed to your object is ok.
So you have to use a polymorphic method, which is not bound to the class
type :

class my_object : object
    method dummy_init : 'a . 'a -> unit
end

This way, you cannot of course store the parameter into a field of my_object
this it is not polymorphic.

Nicolas Cannasse

-------------------
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:[~2003-06-04  3:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-04  3:07 Lex Stein
2003-06-04  3:31 ` Nicolas Cannasse [this message]
2003-06-04 17:30   ` Karl Zilles

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='002301c32a49$bef062b0$2413f9ca@WARP' \
    --to=warplayer@free.fr \
    --cc=caml-list@inria.fr \
    --cc=stein@eecs.harvard.edu \
    /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).