-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Sometimes a function capture doesn't capture any values: currently this is represented by a return value of nil.
And we want to support the case of the value nil being captured. We represent this case with a return value of [nil].
We also want to distinguish between multiple captures and a single captures that is an array. This is currently the difference between return values of [1, 2, 3] and of [[1, 2, 3]].
What does [] mean: no values were captured, or an empty array was captured? If the latter, what does [[]] mean?
This is all rather awkward. At least part of the problem is that Ruby doesn't really have multiple return values. We return an array and deconstruct via assignment. Lua does this better: return 1, 2 vs return {1,2}.
Is there a better way?
Ideas:
- use a Maybe monad of some sort.
Nonewould be no capture, whileSome(nil)would be a capture ofnil- But how to represent multiple captures? The natural interpretation of
Some([1,2,3])would be be a single captured array. - Maybe
[Some(1), Some(2), Some(3)]
- Always return an array (or convert a non-Array
xto[x])- Then
[]is no captures, and[nil]is a capture ofnil - What does it mean for a function to return
nil?
- Then
What would such requirements mean for folding captures and other capture-side calculations? Would the use of some sort of Maybe monad require lifting and binding?