Version française
Home     About     Download     Resources     Contact us    
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?
Pixel <pixel@mandrakesoft.com> writes:

[...]

> http://merd.net/pixel/language-study/various/is-a-cow-an-animal/ocaml.listing
> 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...

done: http://merd.net/pixel/language-study/various/is-a-cow-an-animal/ocaml3.listing

it's quite nice. The advantage over the all-in-class solution is that it's
easier to check the types:

* one pb was:

let is_meat_ = function
  | `Beef | `Dead_rabbit | `Dead_human -> true
  | _ -> false

which type "[> `Beef | `Dead_rabbit | `Dead_human] -> bool" doesn't allow 
  is_meat_ (food : [`Grass])

whereas
  let is_meat e = is_meat_ (e :> food_kind)
  is_meat (food : [`Grass])
is allowed (since is_meat : [< food_kind] -> bool)



* I still can't manage to have:

 new_human : int -> ([ `Dead_human], [< food_kind]) animal
all i got is
 new_human : int -> ([ `Dead_human], _[< food_kind]) animal


Please help!
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners