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

Closure equality #176

Open
julianhyde opened this issue Sep 16, 2022 · 0 comments
Open

Closure equality #176

julianhyde opened this issue Sep 16, 2022 · 0 comments

Comments

@julianhyde
Copy link
Collaborator

A closure (lambda plus environment) should equal another closure that is the same code applied to the same environment.

For example, consider this query:

- from i in [1, 2, 3, 2]
=   yield {i, iPlus = fn h => h + i}
=   group iPlus compute count;
val it =
  [{count=1,iPlus=fn},{count=1,iPlus=fn},{count=1,iPlus=fn},{count=1,iPlus=fn}]
  : {count:int, iPlus:int -> int} list

It returns 4 rows, because the two instances of (fn => h + i) {i: 2} do not compare equal, but it should return 3 rows, like this:

val it =
  [{count=1,iPlus=fn},{count=2,iPlus=fn},{count=1,iPlus=fn}]
  : {count:int, iPlus:int -> int} list

Note that in Standard ML, a closure or lambda is not an equality type:

Standard ML of New Jersey v110.79 [built: Sat Oct 26 12:27:04 2019]
- val x = fn i => i;
val x = fn : 'a -> 'a
- x = x;
stdIn:2.1-2.6 Error: operator and operand don't agree [equality type required]
  operator domain: ''Z * ''Z
  operand:         ('Y -> 'Y) * ('X -> 'X)
  in expression:
    x = x
- [] = [];
stdIn:1.5 Warning: calling polyEqual
val it = true : bool

I don't know whether Morel's group should require equality types.

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