Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradual types? #14

Open
moleike opened this issue Jan 25, 2021 · 0 comments
Open

Gradual types? #14

moleike opened this issue Jan 25, 2021 · 0 comments

Comments

@moleike
Copy link
Owner

moleike commented Jan 25, 2021

Jsonnet (the spec) defines the language as dynamically typed. An extension that seems natural to incorporate into Jsonnet is gradual typing with structural subtyping à la TypeScript.

Gradual typing enables mixing typed and untyped code, where users decide where (or when) to add type annotations to increase static checking. Fully annotated programs should be statically type-safe. Programs with no annotations at all should behave as current Jsonnet.

In a first (simpler) approach, we erase type annotations after type checking and interpret the program as if it were dynamically typed. A benefit of this approach is the typechecker becomes a standalone component, and thus it can be used with other compilers. There are some quirks though:

local foo(x) = 
  local bar(y: int) = {};
  bar(x);
foo(true)

The above program should intuitively fail, but it runs to completion.

A more elaborate approach performs run-time type checks at dynamically and statically typed code boundaries, by adding explicit casts. In this case, the type checking could be done after desugaring.

Jsonnet original implementation has a related open issue: google/jsonnet#605

@moleike moleike added the question Further information is requested label May 28, 2021
@moleike moleike removed the question Further information is requested label Jun 22, 2021
@moleike moleike pinned this issue Jun 25, 2021
@moleike moleike unpinned this issue Jan 11, 2022
@moleike moleike changed the title Type checking Gradual types? May 1, 2022
@moleike moleike pinned this issue May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant