Skip to content

Logically Qualified Data Types - automatically infer refinement types

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

bpowers/liquid-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logically Qualified Data Types

This repository contains an implementation in Rust of liquid types on an implicitly-typed variant of ML.

BUILD

This projects requires having the z3 theorem prover library in your library search path.

RUN

As an example, examples/max3.ml defines a function max and applies it to two arguments:

let max = fun x -> fun y -> if x > y then x else y in max 1 -3

You can infer liquid types for this program by running:

$ target/debug/liquid-types examples/max3.ml

This will spit out debugging information about the liquid environment (Γ) and subtyping constraints, the liquid type templates we start with (a), and the liquid type templates after we've iteratively weakened them (min_a), along with the refined types produced by running liquid type inference.

For example, the type inferred for max above is:

max_a1:	F(x_a2: {ν: Int | 0 ≤ ν} → F(y_a3: {ν: Int | true} → {ν: Int | 0 ≤ ν ∧ x_a2 ≤ ν ∧ y_a3 ≤ ν}))

(the _a$N suffix on variables can be ignored, it is added during A-normalization)

There are additional programs in the examples/ directory, and feel free to try your own! If you hit any problems, please open an issue.

IMPLEMENTED

Most of the paper is implemented, including:

  • The liquid type inference algorithm, including constraint generation and iterative weakening.
  • lexing/parsing/interpreting a subset of an implicitly-typed ML-like language
  • Hindley-Milner type inference
  • A-normalization
  • Alpha renaming

NOT IMPLEMENTED

  • Specifying Q (the set of liquid type templates) on the command line - to change Q edit the definition in main.rs.
  • Higher order polymorphic functions.
  • Types -- instantiation or polymorphism, only built-in bool and int types are available.
  • Pending substitutions in liquid type parameters.
  • Liquid type inference for arrays, array operations like sub, set and the built-in function len.

QUIRKS

Subtraction: - make sure there are spaces around - like in k - 1. k-1 doesn't currently work (it is lexed as two tokens, k and -1).

LICENSE

Dual-licensed under the MIT and Apache licenses, as is Rust + the LALRPOP parser generator. The lexer is heavily borrowed from LALRPOP.

About

Logically Qualified Data Types - automatically infer refinement types

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages