{-# LANGUAGE GHC2021 #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} module M where import Data.Kind import GHC.TypeLits data SimplePattern = SP1 | SP2 | SP3 Type data Msgx = MsgDoThis | MsgDoThat Type type family Msg c where Msg X = Msgx -- if you uncomment this it compiles -- type instance Msg X = Msgx -- if you uncomment this it fails class D c where type FromPat c (sp :: SimplePattern) :: Maybe (Msg c) data X instance D X where type FromPat X SP1 = 'Just (MsgDoThis :: Msg X) type FromPat X SP2 = 'Nothing type FromPat X (SP3 t) = 'Just (MsgDoThat t)