Last active
January 2, 2019 10:07
-
-
Save merijn/6130082 to your computer and use it in GitHub Desktop.
Type family that disallows certain types for type variables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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