caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Polymorphic Variants and Objects
@ 2001-12-18 14:37 Jim Farrand
  2001-12-20  2:07 ` Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Farrand @ 2001-12-18 14:37 UTC (permalink / raw)
  To: caml-list


Take a look at the following OCaml class type definition:

class type foo =
  object
    method bar: [ `A | `B ] 
  end

I want to be able to relax the type of bar so that it can return any variant 
tag, rather than being limited to `A or `B.

Is this possible?  I tried

class type foo =
  object
    method bar: [> ] 
  end

but this is rejected on the grounds that

The method bar has type [> ] where .. is unbound

Any suggestions?

Regards,
Jim
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Polymorphic Variants and Objects
  2001-12-18 14:37 [Caml-list] Polymorphic Variants and Objects Jim Farrand
@ 2001-12-20  2:07 ` Jacques Garrigue
  2001-12-20  9:44   ` Jim Farrand
  0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2001-12-20  2:07 UTC (permalink / raw)
  To: jim; +Cc: caml-list

From: Jim Farrand <jim@farrand.net>

> Take a look at the following OCaml class type definition:
> 
> class type foo =
>   object
>     method bar: [ `A | `B ] 
>   end
> 
> I want to be able to relax the type of bar so that it can return any variant 
> tag, rather than being limited to `A or `B.

What about:

class type ['a] foo =
  object
    constraint 'a = [> `A | `B]
    method bar : 'a
  end

Since you want the variant to be polymorphic, you have to bind its
variable somewhere.

---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Polymorphic Variants and Objects
  2001-12-20  2:07 ` Jacques Garrigue
@ 2001-12-20  9:44   ` Jim Farrand
  0 siblings, 0 replies; 3+ messages in thread
From: Jim Farrand @ 2001-12-20  9:44 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

On Thursday 20 December 2001 02:07, Jacques Garrigue wrote:

> Since you want the variant to be polymorphic, you have to bind its
> variable somewhere.

Thanks, that's exactly what I needed to know.

Regards,
Jim
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-12-20  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-18 14:37 [Caml-list] Polymorphic Variants and Objects Jim Farrand
2001-12-20  2:07 ` Jacques Garrigue
2001-12-20  9:44   ` Jim Farrand

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