Fergus Henderson:
> One example is the case where you already have existing code that
> creates a heterogenous collection, and you want to extract an
> element from that heterogenous collection, and then if it is
> a member of a particular type class perform action A otherwise
> perform action B, *without* modifying the existing code.
OK, it sounds like this would indeed require 'tweaking' (at least)
the existing code, it the representation of the collection doesn't
admit the required operations.
> The dynamic typing extensions in GHC/Hugs will let you cast to a particular
> type, but they won't let you check whether that a dynamically typed value
> is a member of a particular type class, or cast such a value to a type class
> constrained type.
I had noticed that apparent limitation myself, while pondering a certain
problem (to which it turns out that (I think) existential types are
an adequate solution, in that case).
It would be interesting to investigate adding 'dynamic classes' to
Haskell, but it introduces the issue of what type to give the resulting
function: I think I'd want to clearly distinguish between a genuine
(boundedly) polymorphic function, and one which covertly does a case
analysis of the (sub-)classes of its argument.
Cheers,
Alex.