Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flow type-level lists
// @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
You can’t perform that action at this time.