Skip to content

Instantly share code, notes, and snippets.

@LukaHorvat
Created August 18, 2017 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukaHorvat/8e9a1af8ce2ca0b09c6902208650a6b6 to your computer and use it in GitHub Desktop.
Save LukaHorvat/8e9a1af8ce2ca0b09c6902208650a6b6 to your computer and use it in GitHub Desktop.
Without
type family Elem (x :: k) (xs :: [k]) :: Bool where
Elem x '[] = 'False
Elem x (x ': xs) = 'True
Elem x (y ': xs) = Elem x xs
type family If (condition :: Bool) (t :: k) (e :: k) :: k where
If 'True t e = t
If 'False t e = e
type family Without (xs :: [k]) (ys :: [k]) :: [k] where
Without xs '[] = xs
Without '[] ys = '[]
Without (x ': xs) ys = If (x `Elem` ys) (Without xs ys) (x ': Without xs ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment