Last active
March 1, 2020 22:16
-
-
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
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
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