Open andrewthad opened 9 years ago
I do some things with reifying type class dictionaries in Frames
, too. See here for example. I think I have a couple variations of this in various places, but I'm not sure what the maximally useful shape is yet.
I've faced similar problem when I needed to extract attribute type information, but not the attribute value itself. I've also created recordProxy :: forall f . Rec (Proxy :. f) rs
function (but my version is based on type classes, your seems to be more elegant) and reifyProxyConstraint :: RecAll f rs c => proxy c -> Rec (Proxy :. f) rs -> Rec (ProxyDict c :. f) rs
for ProxyDict which I defined as data ProxyDict c a where ProxyDict :: c a => Proxy a -> ProxyDict c a
. My code is here.
Your approach seems to be more generic and it definitely should be explored, because current version of reifyConstraint
not usable with proxies.
I occasionally find that I need a record of constraints without actually having values. The
Dict
definition in vinyl requires a value, I started by passingundefined
(eww...), but I have now settled on an alternativeMyDict
formulation that I am using. The relevant parts of my code look like this:This is particularly more useful when you're dealing with the
Typeable
constraint or when you're just trying to extract methods from a typeclass (I know that sounds weird but I have a reasonable use case for it). At any rate, I was wondering if there was a way thatDict
andreifyConstraint
could somehow be built on top of the alternatives I have written (as mine require strictly less information) and then both possibilities could be offered from the same core code. Just food for thought.