[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@k...> |
| Subject: | Re: [Caml-list] Is a Cow an Animal? |
From: Pixel <pixel@mandrakesoft.com>
> * 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])
This is to avoid _too_ weak typings, which would allow for bad typos.
The more direct solution is
let is_meat_ = function
| #meat_kind -> true
| #vegetable_kind -> false
> * 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
Classical solution is eta-expansion
let new_human n : ([`Dead_human], [< food_kind ]) animal =
new animal `Human `Dead_human n
should work.
Basically, for closed world problems polymorphic variants work
generally better than object encodings. If you want it open world,
this gets more subtle.
Jacques Garrigue
-------------------
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