caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Some questions about type inference
@ 2000-10-26 13:30 Benedikt Rosenau
  2000-10-26 16:46 ` John Max Skaller
  2000-10-26 16:56 ` Didier Remy
  0 siblings, 2 replies; 3+ messages in thread
From: Benedikt Rosenau @ 2000-10-26 13:30 UTC (permalink / raw)
  To: caml-list

I have played with covariance. Namely, I tried to define a class
of objects with a method "eat" who would only eat objects defining
a method "eat" themselves.

The direct approach fails:

  class virtual broken_carnivore =
    object
      method virtual eat: <eat: _; ..> -> unit
    end

since there is an unbound type variable in the ellipsis.


However, the following works (more or less):

  class virtual ['a] carnivore =
    object
      constraint 'a = ('a) #carnivore
      method virtual eat: <eat: _; ..> -> unit
    end

and I can only speculate how this binds the type variable.


Another piece de resistence for my understanding is the following:
  match []::[] with a::b -> a = [] & b = []
works, while
  match []::[] with a::b -> a = b
gives a type error.
   Benedikt



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

end of thread, other threads:[~2000-10-26 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-26 13:30 Some questions about type inference Benedikt Rosenau
2000-10-26 16:46 ` John Max Skaller
2000-10-26 16:56 ` Didier Remy

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