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

Add support for ad-hoc variables in refinement types #645

Open
bvssvni opened this issue Sep 20, 2019 · 0 comments
Open

Add support for ad-hoc variables in refinement types #645

bvssvni opened this issue Sep 20, 2019 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Sep 20, 2019

For example:

fn add(a: any, b: any) -> any { ... }
    all T { (T f64, T f64) -> T f64 }

This is needed since addition on ad-hoc types is only valid for the same ad-hoc type.

A "none ad-hoc type" is a type f64 which ad-hoc type is T f64.

The all quantifier uses the semantics that "none ad-hoc type" is quantified over. This way, one only needs to write a single rule for all ad-hoc types plus the default case. The normal ad-hoc rule is not involved, since one can simply leave out the case e.g. (f64, f64) -> f64 and use all T { (T f64, T f64) -> T f64 } instead.

The "none ad-hoc type" of the previous arguments is lifted to T. This means that for binary operators, you can leave out ad-hoc type of the left argument and still pass the type check.

fn km(a: f64) -> km f64 {return clone(a)}

fn main() {
    println(2 + km(4)) // Works fine.
    println(km(4) + 2) // ERROR
}
bvssvni added a commit to bvssvni/dyon that referenced this issue Sep 21, 2019
See PistonDevelopers#645

Use the semantics that none ad-hoc type is quantified over by `all`.

- Added `Type::all_ext`
- Added `Type::bind_ty_vars`
- Added `Type::insert_var`
- Added `Type::insert_none_var`
- Added `T` lazy static string
- Added some refine quantifier tests
- Updated `add` in “lib.dyon”
- Updated `add` extra type information
- Added support for type quantifier in syntax
- Push type variable names to “ty” node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant