caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Polymorphic variants and inheritance
@ 2012-10-25 11:54 Ivan Gotovchits
  2012-10-25 11:57 ` Didier Cassirame
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Gotovchits @ 2012-10-25 11:54 UTC (permalink / raw)
  To: caml-list


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?"...

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

end of thread, other threads:[~2012-10-26  3:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-25 11:54 [Caml-list] Polymorphic variants and inheritance Ivan Gotovchits
2012-10-25 11:57 ` Didier Cassirame
2012-10-25 12:14   ` Didier Cassirame
2012-10-26  3:37     ` Ivan Gotovchits

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