type odds = [`One | `Three ]
type evens = [`Two | `Four ]
type numbers = [ odds | evens ]

class type ['a] number = object
  constraint 'a = [< numbers]
  method category: 'a
end

class type odd = object
  inherit [odds] number
  method category: odds
end

class type even = object
  inherit [evens] number 
  method category: evens
end

It's probably even better like this :)

Cheers,

didier


2012/10/25 Didier Cassirame <didier.cassirame@gmail.com>
Hi Ivan,

You may use parameterized classes like this :

type odds = [`One | `Three ]
type evens = [`Two | `Four ]
type numbers = [ odds | evens ]

class type ['a] number = object
  constraint 'a = [< numbers]
  method category: 'a
end

class type ['a] odd = object
  inherit ['a] number

  constraint 'a = odds

  method category: 'a
end


class type ['a] even = object
  inherit ['a] number 
  constraint 'a = evens
  method category: 'a
end

This passes the compilation.

didier


2012/10/25 Ivan Gotovchits <ivg@ieee.org>

Here a simple example that illustrates the problem:

   type odds = [`One | `Three ]
   type evens = [`Two | `Four ]
   type numbers = [ odds | evens ]

   class type number = object
     method category: numbers
   end

   class type odd = object
     inherit number
     method category: odds
   end


   class type even = object
     inherit number
     method category: evens
   end



It fails to compile, stating the following error:
       The method category has type odds but is expected to have type numbers
       Type odds = [ `One | `Three ] is not compatible with type
         numbers = [ `Four | `One | `Three | `Two ]
       The first variant type does not allow tag(s) `Four, `Two

Just by theory, odds are covariant to numbers, so this kind of subtyping
can be done. Is it possible to persuade compiler?

--
         (__)
         (oo)
   /------\/
  / |    ||
 *  /\---/\
    ~~   ~~
...."Have you mooed today?"...

--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs