Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Created April 6, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancavalier/cce7dd5ef769db6279fbd4aafa7bb711 to your computer and use it in GitHub Desktop.
Save briancavalier/cce7dd5ef769db6279fbd4aafa7bb711 to your computer and use it in GitHub Desktop.
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