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: Didier Remy <Didier.Remy@i...>
Subject: Re: Some questions about type inference
> Namely, I tried to define a class
> of objects with a method "eat" who would only eat objects defining
> a method "eat" themselves.
...
>  However, the following works (more or less):

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

This is correct but maybe cumbersome. You may also write: 

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

which may be clearer.

BTW, if you are trying variations on the well-known cow/animal example
introduced by David Shang ["Is a cow an animal?", Unpublished note January
1996] you may find a discussion of this example together with a version in
Ocaml at:

        http://cristal.inria.fr/~remy/work/virtual/
        >> [Section] Expressiveness and abstraction

-Didier