caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: caml-list@yquem.inria.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Object typing
Date: Sun, 10 Jul 2005 10:20:37 +1000	[thread overview]
Message-ID: <20050710002037.GA8569@pulp.anu.edu.au> (raw)
In-Reply-To: <42D063EC.3040900@earthlink.net>

On Sat, Jul 09, 2005 at 05:55:24PM -0600, Matthew O'Connor wrote:
> I'm at a loss as how to proceed.  Any other suggestions or ideas or
> better solutions would be greatly appreciated.  Thank you.

you can try to restrict the polimorphy variant type (and maybe 
having more than one type to make the hierarchy explicit).

hope this helps.
:)
p

type t = [ `Predator | `Entity | `Chicken ];;

class type ientity =
object
method is_a : t -> bool
end

class entity : ientity =
object
  method is_a = function
  |`Entity -> true
  |#t -> false
end

class predator =
object
  inherit entity as super
  method is_a = function
  |`Predator -> true
  |#t as v -> super#is_a v
end

let ent = new predator;;
print_endline (string_of_bool (ent#is_a `Predator));; (* returns true *)
print_endline (string_of_bool (ent#is_a `Entity));; (* returns true *)
print_endline (string_of_bool (ent#is_a `Chicken));; (* returns false *)


-- 
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++ 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html


  reply	other threads:[~2005-07-10  0:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09 23:55 Matthew O'Connor
2005-07-10  0:20 ` Pietro Abate [this message]
2005-07-10  6:19   ` [Caml-list] " Matthew O'Connor
2005-07-10 18:25 ` Stephane Glondu
2005-07-10 22:06 ` Christophe TROESTLER
2005-07-11  6:23   ` Matthew O'Connor
2005-07-11  7:18   ` Remi Vanicat
2005-07-11  8:22     ` Jacques Garrigue
2005-07-11  9:16       ` Marcin 'Qrczak' Kowalczyk

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=20050710002037.GA8569@pulp.anu.edu.au \
    --to=pietro.abate@anu.edu.au \
    --cc=caml-list@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    /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).