Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2002-09-23 (09:49)
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

	- Andreas

Andreas Rossberg,

"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 Archives:
Bug reports: FAQ:
Beginner's list: