Version française
Home     About     Download     Resources     Contact us    
Browse thread
Object typing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pietro Abate <Pietro.Abate@a...>
Subject: Re: [Caml-list] Object typing
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