caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: guillaume.yziquel@citycable.ch
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic method.
Date: Thu, 10 Sep 2009 21:48:27 +0900 (JST)	[thread overview]
Message-ID: <20090910.214827.104047449.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <4AA8F16F.1040009@citycable.ch>

There are already polymorphic methods in ocaml.
The syntax for your example would be:

class myobject = object
  method id : 'a. 'a -> 'a = fun x -> x
end

A "polymorphic" keyword might seem simpler, but it would be complex to
handle the case where a polymorphic method type contains also class
parameters:

class ['a] cell (x : 'a) = object
  method pair : 'b. 'b -> 'a * 'b = fun y -> (x,y)
end

More generally, you might end up with types more polymorphic than you
expected, and since differently instantiated polymorphic method types
are incompatible, this would be a problem.

Jacques Garrigue

From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
> When developing with objects in OCaml, I'm quite often faced with
> polymorphic methods.
> 
> Such as:
> 
> class myobject = object
>   method id x = x
> end
> 
> Sometimes you have many methods that you're tinkling with, and the
> compiler keeps saying to you that 'a is inbound in this class
> declaration.
> 
> I'm therefore wondering if it would be a good idea to have a keyword
> 'polymorphic', and one would write
> 
> class myobject = object
>   polymorphic method id x = x
> end
> 
> The polymorphic keyword would be a hint that the method is polymorphic
> and that there is no need to look at the class' type parameters.
> 
> -- 
>      Guillaume Yziquel
> http://yziquel.homelinux.org/


  reply	other threads:[~2009-09-10 12:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4AA191F3.5000004@yziquel.homelinux.org>
2009-09-10 12:30 ` Guillaume Yziquel
2009-09-10 12:30 ` Guillaume Yziquel
2009-09-10 12:48   ` Jacques Garrigue [this message]
2009-09-10 13:05     ` [Caml-list] " Guillaume Yziquel
2009-09-10 14:21       ` Jacques Garrigue
2009-09-10 19:14         ` Guillaume Yziquel
2009-09-11  7:14           ` blue storm
2009-09-11  8:20             ` Guillaume Yziquel
2009-09-11  8:18           ` Jacques Garrigue
2009-09-11  9:40             ` Guillaume Yziquel

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=20090910.214827.104047449.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=guillaume.yziquel@citycable.ch \
    /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).