Created
August 16, 2021 22:28
-
-
Save ehrenmurdick/e5fff5900ff62274e42fa3c3613f5c07 to your computer and use it in GitHub Desktop.
Peano numbers in facebook flow!
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 | |
type Zero = {} | |
type Succ<M> = { succ: M } // doesn't matter what the type actually has in it | |
type P = Zero | Succ<P> | |
type Increment = <P>(P) => Succ<P> | |
type Prev = <P>(Succ<P>) => P | |
type One = $Call<Increment, Zero> | |
type Two = $Call<Increment, One> | |
type Three = $Call<Increment, Three> | |
// the ("": any) is because I just have to have an inhabitant. casting it through any | |
// lets me cast it to anything else, but once it's gone through the first | |
// cast it has a definite type. Flow makes no changes at all to the actual code, | |
// it only checks the type. "Compilation" is to just delete all the flow annotations. | |
// An actual inhabitant of Three would just be the object { succ: {succ: {succ: {}}}} | |
;((("": any): $Call<Prev, Three>): Two) | |
// Delete this line and the error goes away. | |
;((("": any): $Call<Prev, Three>): One) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment