Mapping over constrained existentially qualified higher order type

80 Views Asked by At

I hope I got the terminology right.

I want to do the following:

data Hide a = ∀ b. (A.ToJSON (a b), A.ToJSON b) ⇒ Hide (a b)

mapHide ∷ (∀ c. (A.ToJSON (b c), A.ToJSON c) ⇒ a c → b c) → Hide a → Hide b
mapHide f (Hide a) = (Hide $ f a)

Unfortunately, GHC seemingly can't infere the constraints right and complains with:

Could not deduce (A.ToJSON (b b1)) arising from a use of ‘Hide’
    from the context (A.ToJSON (a b1), A.ToJSON b1)

Is this somehow possible?

1

There are 1 best solutions below

0
Clinton On BEST ANSWER

Changing the function type to something like this might do the trick:

 (A.ToJSON (b c2), A.ToJSON c2) ⇒
 (∀ c. (A.ToJSON (a c), A.ToJSON c) ⇒ a c) 
    → b c2)

Also avoid using '$' as it kills polymorphism.