On 9/7/22 11:37, John Cowan wrote:
On Wed, Sep 7, 2022 at 1:04 AM Per Bothner <[email protected] <mailto:[email protected]>> wrote: I haven't really been following the discussions, but I want to point out that Kawa has implicit forcing for both (delay ...) and (future ...). (display ...) does an implicit force; (write ...) does not. Good point; there should have been some discussion of the ad-hoc polymorphic procedures for I/O. But do all other ad-hoc polymorphic procedures force their arguments, like + or `string-set!`?
Most do. `list` doesn't but it may not count as "ad-hoc polymorphic": #|kawa:4|# (write (+ (delay 3) (future 12))) 15 #|kawa:5|# (write (list (delay 3) (future 12))) (#<promise - not forced yet> #<future Thread-4>) My hope is that promises with implicit forcing provides a useful model for functional progarmming with lazy evaluation - but with lazy having to be explict and eager the default, in contrast to (say) Haskell. This interacts with type-checking: The type 'integer' refers to an actual forced value. (This makes it easier to generate effecient code than if we have to check for laziness.) The type 'lazy[integer]' refers to a possibly-lazy value which when forced is an integer. You can freely convert between the two, but converting a lazy[integer] to integer does a force if needed. #|kawa:1|# (define (list2-lazy x::promise[integer]) (list x x)) #|kawa:2|# (write (list2-lazy (delay 34))) (#<promise - not forced yet> #<promise - not forced yet>) #|kawa:3|# (define (list2-eager x::integer) (list x x)) #|kawa:4|# (write (list2-eager (delay 34))) (34 34) There are probably some bugs and other issues in how Kawa handles promises (because of limited use and testing), and also partly because how the JVM handles parameterized types. (You can't at runtime check if an object is a Promise[integer] or a Promize[string].) However, I do think this is an under-explored design space. https://www.gnu.org/software/kawa/Lazy-evaluation.html -- --Per Bothner [email protected] http://per.bothner.com/
