Version française
Home     About     Download     Resources     Contact us    
Browse thread
Some questions about type inference
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Benedikt Rosenau <Benedikt.Rosenau@d...>
Subject: Some questions about type inference
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