Created
April 6, 2018 13:46
-
-
Save briancavalier/cce7dd5ef769db6279fbd4aafa7bb711 to your computer and use it in GitHub Desktop.
Flow type-level lists
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-level lists | |
type Empty = [] | |
// Type-level tail function | |
type Tail<L> = $Call<FTail, L> | |
interface FTail { | |
(Empty): Empty, | |
<H, T>([H, T]): T | |
} | |
// Use plain tuples for cons | |
type L1 = [string, Empty] | |
type L2 = [number, L1] | |
type L3 = [boolean, L2] | |
// Call tail | |
type L4 = Tail<L3> | |
type L5 = Tail<L4> | |
// Ok, let's provide some values to prove it works | |
let l2: L2 = [1, ['a', []]] | |
let l2Also: L4 = l2 | |
let l5: L5 = ['b', []] | |
let l2Again: [number, L5] = [1, l5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment