Using Proxy in a TypeClass
Using Proxy in a TypeClass I'm trying to do something similar to this question. I'd like to define a typeclass class Wrapper f where wrap :: a -> f a unwrap :: f a -> a name :: Proxy (f a) -> String and then define instance (IsString a, FromJSON a, Wrapper f) => FromJSON (f a) where parseJSON (String s) = wrap <$> pure (fromString $ unpack s) parseJSON invalid = typeMismatch (name (Proxy :: Proxy (f a))) invalid But I'm getting an error saying that Could not deduce (Wrapper f0) arising from a use of ‘name’ from the context: (IsString a, FromJSON a, Wrapper f) bound by the instance declaration at src/Model/Wrapper.hs:29:10-62 The type variable ‘f0’ is ambiguous It's not really clear to me why this doesn't work and if it possible to fix it somehow ...
