'Reversing / enriching typeclass resolution in haskell
Is there any trick to get the "ancestor" proof of a typeclass instance ?
data Dict c = c => Dict
newtype Prod a b = MkProd {getProd :: (a, b)}
class Mk a where mk :: a
instance (Mk a, Mk b) => Mk (Prod a b) where
mk = MkProd (mk, mk)
challenge :: Mk (Prod a b) => Dict (Mk b)
challenge = Dict
-- Could not deduce (Mk b) arising from a use of ‘Dict’
-- from the context: Mk (Prod a b)
Attempting with "UndecidableInstances" yields an overlap error
newtype Prod a b = MkProd {getProd :: (a, b)}
class Make a where make :: a
instance {-# OVERLAPPING #-} (Make a, Make b) => Make (Prod a b) where
make = MkProd (make, make)
instance {-# OVERLAPPABLE #-} (Make (Prod a b)) => Make a where
make = let (MkProd (a, b)) = make @(Prod a b) in a
challenge :: Make (Prod a b) => Dict (Make a)
challenge = Dict -- • Overlapping instances for Make a arising from a use of ‘Dict’
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
