Skip to content

Instantly share code, notes, and snippets.

@merijn
Last active January 2, 2019 10:07
Show Gist options
  • Save merijn/6130082 to your computer and use it in GitHub Desktop.
Save merijn/6130082 to your computer and use it in GitHub Desktop.
Type family that disallows certain types for type variables.
{-# LANGUAGE ConstraintKinds, DataKinds, PolyKinds, TypeFamilies, TypeOperators #-}
import GHC.Exts (Constraint)
type family Restrict (a :: k) (as :: [k]) :: Constraint where
Restrict a (a ': as) = ("Error!" ~ "Tried to apply a restricted type!")
Restrict x (a ': as) = Restrict x as
Restrict x '[] = ()
foo :: Restrict a [(), Int] => a -> a
foo = id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment