caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: pixel@mandrakesoft.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Is a Cow an Animal?
Date: Thu, 18 Apr 2002 21:52:32 +0900	[thread overview]
Message-ID: <20020418215232T.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <lyads1p5s6.fsf@leia.mandrakesoft.com>

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


  reply	other threads:[~2002-04-18 12:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-17 23:40 Pixel
2002-04-18  2:17 ` John Max Skaller
2002-04-18 10:19   ` Pixel
2002-04-18 12:09     ` Pixel
2002-04-18 12:52       ` Jacques Garrigue [this message]
2002-04-18 13:03         ` Pixel
2002-04-18 18:58 ` james woodyatt
2002-04-18 22:44   ` Pixel
2002-04-18 22:57     ` james woodyatt
2002-04-18 23:31       ` Pixel
2002-04-19  0:21   ` Remi VANICAT
2002-04-19  0:51     ` james woodyatt

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=20020418215232T.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=pixel@mandrakesoft.com \
    /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).