Skip to content

Instantly share code, notes, and snippets.

Last active January 2, 2019 10:07
What would you like to do?
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