Closed parsonsmatt closed 2 years ago
Eh, I think the easiest thing to do here is special-case on CallStack
and forward to the newtype
wrapper. That should simplify quite a lot of code. Eventually if CallStack
gets a Show
instance then we can drop all that machinery.
The type
AnnC
is a constraint alias forEq a, Show a, Typeable a
.The functionality of the library absolutely depends on
Typeable a
, but without anything else, thenAnnotation
is "just" aData.Dynamic.Dynamic
value.One of the most obviously useful types to have in there is
CallStack
, which we cannot put in a[Annotation]
because it lacks aShow
instance. I've filed a GHC issue requesting one, but it will be a while before that is resolved.One possibility is to write special support for
CallStack
incastAnnotation
that, if you're trying to cast out aCallStack
, we look for aCallStackAnnotation
instead. This is a bit gross but it completely solves the problem . . if you're usingcastAnnotation
instead ofcast
directly on the underlying value.Maybe what's really necessary here is to use an
Exception
-like subtyping hierarchy with a custom class for doing the conversion.Annotation
is already morally equivalent toSomeException
in that anException e
is just a(Show a, Typeable a)
value. HavingtoAnnotation
andfromAnnotation
as the main methods on the class would provide a neat entry point to this. Then we have:This doesn't help with
CallStack
because we don't have aShow
instance for it, so we still can't writeinstance Annotation CallStack
.