by dependenttypes · 6y ago · 0 comments
data TC x where
DC :: Ord x => x -> TC x -- `Ord x` exists when matching on DC constructor
ex1 :: TC x -> x -> x -> Ordering
ex1 (DC _) a b = compare a b
-- Without constructor match, no Ord instance
ex2 :: TC x -> x -> x -> Ordering
ex2 _ a b = compare a b -- ERROR!
-- This is why the above ex2 definition is an error
badUser :: x -> x -> Ordering
badUser a b = ex2 undefined a b
-- No `TC x` value also means no Ord instance even
-- though no arguments are ignored or undefined
data Proxy x = Proxy
ex2 :: Proxy (TC x) -> x -> x -> Ordering
ex2 Proxy a b = compare a b -- ERROR!