Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: malc <malc@pulsesoft.com>
Cc: caml-list@inria.fr
Subject: Re: Polymorphic variants in class methods
Date: Wed, 11 Oct 2000 11:54:10 -0700 (PDT)	[thread overview]
Message-ID: <Pine.BSF.4.21.0010111129480.2068-100000@shell5.ba.best.com> (raw)
In-Reply-To: <Pine.LNX.4.21.0010090217030.885-100000@home.oyster.ru>

On Mon, 9 Oct 2000, malc wrote:
> # class foo = object method moo = `Bar end;;
> Some type variables are unbound in this type:
>   class foo : object method moo : [> `Bar] end
> The method moo has type [> `Bar] where 'a is unbound
> 
> Someone care to comment on that?

As Jacques Garrigue has pointed out, typing of polymorphic variants is
subtle, and the interaction of polymorphic variant and object typing is 
very subtle. Let me try and explain simply and an expert can tell if I am 
wrong or inaccurate...

Types described by "[>" are polymorphic and can be extended with new
tags, so they have an implicit type variable.

OCaml classes can be polymorphic, but methods must be monomorphic, so 
your example is similar to 

# class foo = object method moo = List.length end;;
Some type variables are unbound in this type:
  class foo : object method moo : 'a list -> int end
The method moo has type 'a list -> int where 'a is unbound

Now, an oft discussed extension to OCaml is polymorphic methods (and an 
even more oft discussed extension would allow polymorphic recursion in 
the core (non OO) language) which would have you explicitly provide 
the type for that method. This was supported in OLabl. I don't know the
OLabl incantation to type your program, but for the example I gave I
think it is 

class foo = object method moo : 'a . 'a list -> int = List.length end;;

One way to make your program typecheck is to define the set of variants
you want to deal with, like so. 

# type t = [`Foo | `Bar | `Baz];;
type t = [ `Foo | `Bar | `Baz]
# class foo = object method moo : t = `Bar end;;  
class foo : object method moo : t end

> P.S. Uhm, like im totaly lost on whats going on here.

Ummm, like I totally hope this helps, dude. :-)

I think you'll want to at least read "Programming with Polymorphic
Variants" which you can download from

    http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/

-- Brian



      parent reply	other threads:[~2000-10-11 19:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-08 22:18 malc
2000-10-11  2:35 ` Jacques Garrigue
2000-10-11 18:54 ` Brian Rogoff [this message]

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=Pine.BSF.4.21.0010111129480.2068-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=malc@pulsesoft.com \
    /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