• code Haskell
    type family FragmentUnique api :: Constraint where
      FragmentUnique (sa :<|> sb)       = Or (FragmentUnique sa) (FragmentUnique sb)
      FragmentUnique (Fragment a :> sa) = FragmentNotIn sa (Fragment a :> sa)
      FragmentUnique (x :> sa)          = FragmentUnique sa
      FragmentUnique (Fragment a)       = ()
      FragmentUnique x                  = ()
    
    type family FragmentNotIn api orig :: Constraint where
      FragmentNotIn (sa :<|> sb)       orig =
        And (FragmentNotIn sa orig) (FragmentNotIn sb orig)
      FragmentNotIn (Fragment c :> sa) orig = TypeError (NotUniqueFragmentInApi orig)
      FragmentNotIn (x :> sa)          orig = FragmentNotIn sa orig
      FragmentNotIn (Fragment c)       orig = TypeError (NotUniqueFragmentInApi orig)
      FragmentNotIn x                  orig = ()
    
    type NotUniqueFragmentInApi api =
        'Text "Only one Fragment allowed per api ‘"
        ':<>: 'ShowType api
        ':<>: 'Text "’."
    ♡ recommended by @Anonymous

Replies (0)