Skip to content

Instantly share code, notes, and snippets.

@MrQubo
Created December 17, 2023 19:05
Show Gist options
  • Save MrQubo/67a3b2a6f9ec3d9ef12e261d7b2a41c8 to your computer and use it in GitHub Desktop.
Save MrQubo/67a3b2a6f9ec3d9ef12e261d7b2a41c8 to your computer and use it in GitHub Desktop.
Implicit constraint on associated type family
{-# LANGUAGE
DerivingStrategies,
TypeFamilies,
PatternSynonyms,
DataKinds
#-}
class (Show (SymbolIdent' p)) => IdentParam p where
data SymbolIdent' p
data SymbolIdent p where
SymbolIdent :: IdentParam p => SymbolIdent' p -> SymbolIdent p
deriving stock instance Show (SymbolIdent p)
data IdentParamName
instance IdentParam IdentParamName where
newtype instance SymbolIdent' IdentParamName = SymbolName' String
deriving stock (Show)
pattern SymbolName s = SymbolIdent (SymbolName' s)
data IdentParamId
instance IdentParam IdentParamId where
newtype instance SymbolIdent' IdentParamId = SymbolId' Int
deriving stock (Show)
pattern SymbolId s = SymbolIdent (SymbolId' s)
data Struct p = Struct (SymbolIdent p)
deriving stock Show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment