Skip to content

Instantly share code, notes, and snippets.

@lylek
Last active March 1, 2020 22:16
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 lylek/24963c1565cc691c25c9adb2402416bd to your computer and use it in GitHub Desktop.
Save lylek/24963c1565cc691c25c9adb2402416bd to your computer and use it in GitHub Desktop.
Constructing pairs using functions as in System F, instead of built-in products
data A = A1 | A2 deriving Show
data B = B1 | B2 | B3 deriving Show
type PairAB x = (A -> B -> x) -> x
pairAB :: A -> B -> PairAB x
pairAB a b g = g a b
fstAB :: PairAB A -> A -- ((A -> B -> A) -> A) -> A
fstAB p = p (\x y -> x)
sndAB :: PairAB B -> B -- ((A -> B -> B) -> B) -> B
sndAB p = p (\x y -> y)
type PairAny a b x = (a -> b -> x) -> x
pairAny :: a -> b -> PairAny a b x
pairAny a b g = g a b
fstAny :: PairAny a b a -> a
fstAny p = p (\x y -> x)
sndAny :: PairAny a b b -> b
sndAny p = p (\x y -> y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment