caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: caml-list@inria.fr
Subject: [Caml-list] Polymorphic variants and inheritance
Date: Thu, 25 Oct 2012 15:54:36 +0400	[thread overview]
Message-ID: <87txtiix6r.fsf@golf.niidar.ru> (raw)


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

             reply	other threads:[~2012-10-25 11:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25 11:54 Ivan Gotovchits [this message]
2012-10-25 11:57 ` Didier Cassirame
2012-10-25 12:14   ` Didier Cassirame
2012-10-26  3:37     ` Ivan Gotovchits

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87txtiix6r.fsf@golf.niidar.ru \
    --to=ivg@ieee.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).