Skip to content

Instantly share code, notes, and snippets.

@compiler-errors
Last active December 1, 2019 08:02
Show Gist options
  • Save compiler-errors/7695ffa040a4fe3b587f63957e67875f to your computer and use it in GitHub Desktop.
Save compiler-errors/7695ffa040a4fe3b587f63957e67875f to your computer and use it in GitHub Desktop.
Lazy types: motivations and syntax

{ 1 } is type lazy number

Functions can require that their parameters be lazy with the ~:

fn times n ~do = if (n <= 0) { nothing } { eval do; times (n - 1) do } (the ; meaning chain evaluation of two expressions)

If a lazy value is passed to a function that doesn't want a lazy value, then the lazy value is automatically evaluated. This, as a consequence means that the definition of the eval function in the language can be as simple as fn eval x = x, since the parameter is x not ~x, any lazy value that is passed to it is automatically evaluated.

Laziness is at most singly nested. It is automatically flattened, that is:

{ { 1 } } is still type lazy number, this is achieved by always strictly evaluating the last (return) expression in a lazy block. Since the last expression in { { 1 } } is { 1 } which is lazy number. Conceptually this can be thought of turning this expression into { eval { 1 } }, but it can probably be done implicitly when type-checking and evaluating a lazy block...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment