Skip to content

Instantly share code, notes, and snippets.

@harpocrates
Last active July 28, 2016 16:57
Show Gist options
  • Save harpocrates/617456ef82948a161c26634e9aa3929e to your computer and use it in GitHub Desktop.
Save harpocrates/617456ef82948a161c26634e9aa3929e to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
-- Subsitute type `x` for type `y` in type `a`
-- Works only for type constructors having up to 4 type arguments...
type family Substitute x y a where
Substitute x y x = y
Substitute x y (k a b c d) = k (Substitute x y a) (Substitute x y b) (Substitute x y c) (Substitute x y d)
Substitute x y (k a b c) = k (Substitute x y a) (Substitute x y b) (Substitute x y c)
Substitute x y (k a b) = k (Substitute x y a) (Substitute x y b)
Substitute x y (k a) = k (Substitute x y a)
Substitute x y a = a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment