Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How to downcast in OCAML
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] How to downcast in OCAML
Tim Freeman wrote:
> 
> For what it's worth (which may not be much), it is possible to write
> classes in OCAML that are downcastable.  Here's how.
> 
> [trick using exception constructors]

Unfortunately, your scheme does not scale to class hierarchies deeper
than 1. Consider for example adding `subsubclass' as a subclass of
`subclass_1'. Then you might want to downcast from `superclass' to
`subclass_1', but your object actually is a `subsubclass'. Your downcast
will fail. You need hierarchical exception constructors to make that
work.

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
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