1 The problem

You can do this quite easily in Java or C++, mutatis mutandis. You can't do this in Haskell, I don't think. You can't actually do this in O'Haskell either, it seems the O' essentially amounts to syntactic sugar.

You can do a weaker form of this with Haskell's Dynamic, where you only have to deal with Bs that are instances of Typeable. But even with that, note that Dynamic/Typeable/TypeRep are a bit messy, with instances for Typeable defined for a wide range of known types.

An alternative approach would be to identify your "B" within "A" not per-B but per-(up,down). This would allow for instance separate (up,down) for the same B such that

down1 . up2 = Nothing
down2 . up1 = Nothing

Of course this can be done with Dynamic too, by defining dummy types. But it's ugly. A better extension is something like extensible data-types. This allows a type to be defined as "open", which can later be extended by disjoint union. Here's a sample syntax that achieves my OO test: