Typechecking closures is hard, and I’m a little confused by it. Is it an object w/ the closed values in the object? But then the type is only the type of the function as it can be called. So where do the types of the closed values disappear to?
Right now I’m kind of on the fence for whether to have it be a Leema object that implements some kind of callable interface. Then I have to go through the trouble of implementing the callable interface and somehow making the closed types disappear.
The alternative is to make a special native closure value that holds whatever data it needs to and knows how to report the type properly. I’m leaning this way. It’s less of a language-based implementation, but it should be faster to build and will almost certainly be faster to execute.
Of course many languages have implemented this previously, so the answers are probably out there, but usually the implementations for features like this are so deep in that it’s hard to parse out just the bit that would be transferable to Leema.