
In base, the new Data.Proxy module has this handy function: asProxyTypeOf :: a -> Proxy a -> a asProxyTypeOf = const This is nice for restricting the phantom type variable of a Proxy that you have lying around. This use could be generalized to other types with phantom type variables by making the type slightly more polymorphic: asProxyTypeOf :: a -> proxy a -> a Since phantom type variables are a very common pattern, this would make asProxyTypeOf more generally useful. Possible downside: it may be that somebody used asProxyTypeOf to restrict both the phantom type and the "Proxy" type, and that the more polymorphic type for asProxyTypeOf would cause that code to break. I find this pretty unlikely. Perhaps the folks behind the "tagged" package could mention whether this complaint ever came up when it made a similar generalization. ~d

Daniel Wagner
In base, the new Data.Proxy module has this handy function:
asProxyTypeOf :: a -> Proxy a -> a asProxyTypeOf = const
This is nice for restricting the phantom type variable of a Proxy that you have lying around. This use could be generalized to other types with phantom type variables by making the type slightly more polymorphic:
asProxyTypeOf :: a -> proxy a -> a
Since phantom type variables are a very common pattern, this would make asProxyTypeOf more generally useful.
Possible downside: it may be that somebody used asProxyTypeOf to restrict both the phantom type and the "Proxy" type, and that the more polymorphic type for asProxyTypeOf would cause that code to break. I find this pretty unlikely. Perhaps the folks behind the "tagged" package could mention whether this complaint ever came up when it made a similar generalization.
+1, this looks sensible to me. - Ollie
participants (2)
-
Daniel Wagner
-
Oliver Charles