Skip to content

Instantly share code, notes, and snippets.

@FireyFly
Last active March 22, 2019 19:26
Show Gist options
  • Save FireyFly/8cf649dadd7beb2fb5de1d7f65072007 to your computer and use it in GitHub Desktop.
Save FireyFly/8cf649dadd7beb2fb5de1d7f65072007 to your computer and use it in GitHub Desktop.
Flow silliness
// @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