You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
letmy_map (f: int -> int) (xs: int list) =List.map f xs
letbar (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:
letreturn_closure (x: int) : int -> int =if x =0thenfuny : int -> y
elsefuny : 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?
The text was updated successfully, but these errors were encountered:
annenkov
changed the title
Closure do not behave uniformly
Closures do not behave uniformly
Jul 15, 2021
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
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:
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?
The text was updated successfully, but these errors were encountered: