Is there a sane way to apply a polymorphic function to a value of type Dynamic?
For instance, I have a value of type Dynamic and I want to apply Just to the value inside the Dynamic. So if the value was constructed by toDyn True I want the result to be toDyn (Just True). The number of different types that can occur inside the Dynamic is not bounded.
(I have a solution when the types involved come from a closed universe, but it's unpleasant.)
This is perhaps not the sanest approach, but we can abuse my
reflectionpackage to lie about a TypeRep.Given that we can now peek at the
TypeRepof ourDynamicargument and instantiate ourDynamicfunction appropriately.It could be a lot easier if
basejust supplied something likeapDfor us, but that requires a rank 2 type, andTypeable/Dynamicmanage to avoid them, even ifDatadoes not.Another path would be to just exploit the implementation of
Dynamic:and
unsafeCoerceto your ownDynamic'data type, do what you need to do with theTypeRepin the internals, and after applying your function,unsafeCoerceeverything back.