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

Restricting equality to be less polymorphic than it is #510

Closed
nikswamy opened this issue Apr 7, 2016 · 9 comments
Closed

Restricting equality to be less polymorphic than it is #510

nikswamy opened this issue Apr 7, 2016 · 9 comments

Comments

@nikswamy
Copy link
Collaborator

nikswamy commented Apr 7, 2016

We should implement something like this:

//in prims.fst
assume type HasEq: Type -> GTot Type0
assume _: HasEq int
assume _: HasEq bool
val (=) : #a:Type{HasEq a} -> a -> a -> Tot bool

//programmer writes t
type t =
| MkT : int -> int -> t
assume _:HasEq t //compiler generated


//programmer writes s
type s (a:Type) =
| MkS : a -> int -> t
assume _:forall a. HasEq a ==> HasEq (s a)


//programmer writes s
type s' =
| MkS' : (int -> Tot int) -> s'
//compiler generates no assumptions


//programmer write sint
new type sint
//compiler generates no assumptions
@msprotz
Copy link
Collaborator

msprotz commented Apr 7, 2016

Seems like basic type classes. JK reported a problem where polymorphic equality of bigints doesn't work; can we do something like:

assume val HasEq: a:Type -> (f: a -> a -> bool) -> GTot Type0
val (=) : #a:Type{HasEq f a} -> x:a -> y:a -> Tot (z:bool{z = f x y})

// programmer-defined type
type s = ... something custom ...
let cmp_s x y =
  ... custom comparison function ...
assume _:HasEq s cmp_s

So that the programmer can not only specify which types are comparable, but also specify a comparison function.

@aseemr
Copy link
Collaborator

aseemr commented Apr 7, 2016

We would also need a ghost version of op =, that allows logical reasoning about equality of types excluded by HasEq (such as arrows).

@catalin-hritcu
Copy link
Member

If there was a #needs-metatheory tag this would be a great candidate. Type theory and a very fuzzy notion of equality don't really mix.

@catalin-hritcu
Copy link
Member

@aseemr You might be talking about ==, F*'s strangely heterogenous equality?

@nikswamy
Copy link
Collaborator Author

@msprotz : For the record, as per our discussion, HasEq f is even trickier, since we would need f to coincide with the language's logical notion of equality. We agreed on my original post.

@aseemr
Copy link
Collaborator

aseemr commented Jun 17, 2016

The design of this feature is here: https://github.com/FStarLang/FStar/wiki/Deriving-hasEq-predicate-for-inductive-types,-and-types-of-equalities-in-F*. Comments and suggestions are most welcome.

I can pass the F* universe regressions (in has_eq_impl branch). Issue project-everest/mitls-fstar#70 tracks the port of mitls to this change.

@ad-l
Copy link
Contributor

ad-l commented Jul 6, 2016

I'm late to the party but what is the current status of this?

@aseemr
Copy link
Collaborator

aseemr commented Jul 6, 2016

@ad-l, as of few days back, F* universe regressions passed with this feature. Making it work for mitls needs some more work. I am hoping to get back to it later this week or early next week.

@aseemr
Copy link
Collaborator

aseemr commented Jul 21, 2016

This has been merged to the master branch.

@aseemr aseemr closed this as completed Jul 21, 2016
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

5 participants