Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Is a Cow an Animal?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pixel <pixel@m...>
Subject: Re: [Caml-list] Is a Cow an Animal?
John Max Skaller <> writes:


> You ask in the title "Is a cow an animal?". The answer is no.

well, it depends how you define your animal. It *can* be as seen at
(written by famous guys :)

> Use a variant, give up on classes:


> You can do a bit better sometimes, by recognising
> some commonality:
> type Animal = {
>   animal_common:animal_part;
>   animal_variant:animal_split
> }
> type animal_split = Horse of horse | Cow of cow
> ...
> so that the horse type only contains features unique
> to horses. But you should really forget abstraction,
> and just build concrete data structures: its really
> just a large in memory database, after all:
> you really won't gain much hiding the representation here.

well, i don't *want* to give up concrete data structures, I'm just trying to
write the thing. I don't care wether if it's abstract or not. Any working
solution accepted.
uses a variant for the kind (I just changed it, it was a string)

I've still kept the class to allow sharing of fields.

BUT this solution doesn't allow a stricter checking alike ocaml2.listing or
c++2.listing. The reason is that you can't parameter the class with values
(like (Vegetable Carrot)) only types. 

Maybe this is possible with polymorphic variants (?), I'll try...
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: