{-# LANGUAGE DataKinds, OverloadedLabels, TypeFamilies #-} module Main where import Data.Proxy import GHC.TypeLits import GHC.OverloadedLabels data Ei (l1 :: Symbol) a (l2 :: Symbol) b = Lef a | Rig b newtype WasLabel s = WasLabel String instance (KnownSymbol s, s ~ s') => IsLabel s (WasLabel s') where fromLabel = WasLabel (symbolVal (Proxy @s)) was :: forall s a b l1 l2. (KnownSymbol s, KnownSymbol l1, KnownSymbol l2) => WasLabel s -> Ei l1 a l2 b -> Bool was (WasLabel s) (Lef _) = s == symbolVal (Proxy @l1) was (WasLabel s) (Rig _) = s == symbolVal (Proxy @l2) main :: IO () main = do let x = Lef 10 :: Ei "foo" Int "bar" Char y = Rig 'b' :: Ei "foo" Int "bar" Char print (was #foo x) print (was #bar x) print (was #foo y) print (was #bar y)