From: Didier Cassirame <didier.cassirame@gmail.com>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Polymorphic variants and inheritance
Date: Thu, 25 Oct 2012 14:14:58 +0200 [thread overview]
Message-ID: <CA+LkvyomeUuZS3MDgyuCuHzWVWmvQOP3hXyM2FkC2XEJaDv-eA@mail.gmail.com> (raw)
In-Reply-To: <CA+LkvyqDV6CEWUtC0RvjGUWFrnR2aA9SpOFALDg1iix5LqMKVg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2332 bytes --]
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
>>
>
>
[-- Attachment #2: Type: text/html, Size: 4130 bytes --]
next prev parent reply other threads:[~2012-10-25 12:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-25 11:54 Ivan Gotovchits
2012-10-25 11:57 ` Didier Cassirame
2012-10-25 12:14 ` Didier Cassirame [this message]
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=CA+LkvyomeUuZS3MDgyuCuHzWVWmvQOP3hXyM2FkC2XEJaDv-eA@mail.gmail.com \
--to=didier.cassirame@gmail.com \
--cc=caml-list@inria.fr \
--cc=ivg@ieee.org \
/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