Last active
March 22, 2019 19:26
-
-
Save FireyFly/8cf649dadd7beb2fb5de1d7f65072007 to your computer and use it in GitHub Desktop.
Flow silliness
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
// @flow | |
// adapted from flown | |
type Is<A, B> = $Call< | |
& (<A, B: A>(...args: [A, B]) => $Call<((B) => true) & (() => false), A>) | |
& (() => false) | |
, A, B>; | |
// Peano arithmetic | |
class S<T> {} | |
// 0, S<0>, S<S<0>>, ... | |
type Inc<A> = S<A>; | |
type Dec<A> = $Call<<T>(S<T>) => T, A>; | |
type Add<A, B> = $Call< | |
& ((0, B) => B) | |
& (<T>(S<T>, B) => Add<T, S<B>>) | |
, A, B>; | |
type Zero = 0; | |
type One = S<Zero>; | |
type Two = S<One>; | |
type Three = S<Two>; | |
// Test Inc | |
(true: Is<Three, Inc<Two>>); | |
(false: Is<Two, Inc<Two>>); | |
// Test Dec | |
(true: Is<Two, Dec<Three>>); | |
(false: Is<Three, Dec<Three>>); | |
// Test Add | |
(true: Is<Three, Add<One, Two>>); | |
(true: Is<Three, Add<Two, One>>); | |
(false: Is<Three, Add<One, One>>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment