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

Closures do not behave uniformly #264

Open
annenkov opened this issue Jul 15, 2021 · 0 comments
Open

Closures do not behave uniformly #264

annenkov opened this issue Jul 15, 2021 · 0 comments

Comments

@annenkov
Copy link

I hit the following issue when using closures in Liquidity.

The example below does not compile giving Types ((int -> int)[@closure :int]) and int -> int are not compatible

let my_map (f : int -> int) (xs : int list) =
  List.map f xs
  
let bar (i : int) (xs : int list) =
  my_map (fun (x : int) -> x + i) xs

It seems like types of closures get extra typing information about the environment wrt. which they are closed.
The same problem prevents returning closures from different branches, that are supposed to have the same type:

let return_closure (x : int) : int -> int =
  if x = 0 then fun y : int -> y
  else fun y : int -> x + y

In this case, the type of the second branch is ('c4 -> int)[@closure :int], while I expected it to be of a function type.

This problem disallows many usual functional programming patterns. We are currently working on extracting verified Liquidity code from the Coq proof assistant and in several cases code didn't compile because of this issue with closures.

Would it be possible to fix closures so the types of variables didn't show up in the type of a closure?

@annenkov annenkov changed the title Closure do not behave uniformly Closures do not behave uniformly Jul 15, 2021
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