First-class lazy evaluation#264
Conversation
ppolesiuk
left a comment
There was a problem hiding this comment.
The proposed changes look great. They are in the spirit of effect system of Fram, and I opt for merging them into the upstream. Before that, I would change the effect of the extern functions (see comments below). Moreover, I would like to see some test, even trivial, just to make CI to try parse and typecheck this file.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new module for first-class lazy values (suspensions) that enables deferred computation with memoization. The implementation provides lazy evaluation semantics where computations are executed only when needed and results are cached for subsequent accesses.
Key Changes:
- Added
Lazymodule with suspension data structures and operations - Implemented lazy evaluation with memoization using internal state management via references
- Provided public API for creating, forcing, and mapping lazy values
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ppolesiuk
left a comment
There was a problem hiding this comment.
Now, the PR is ready for merging. Thanks!
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| end | ||
|
|
||
| {## Creates new lazy value with mapped results. ##} | ||
| pub method map {X : type} (self : Lazy X) f = |
There was a problem hiding this comment.
The map method's return type is not constrained. The parameter f should have an explicit type signature like f : X -> Y to ensure type safety and make the function's contract clear.
| pub method map {X : type} (self : Lazy X) f = | |
| pub method map {X Y : type} (self : Lazy X) (f : X -> Y) : Lazy Y = |
| end | ||
|
|
||
| {## Creates new lazy value with mapped results. ##} | ||
| pub method map {X : type} (self : Lazy X) f = |
There was a problem hiding this comment.
The map method only declares the input type X but not the output type. Consider adding {X Y : type} and typing f : X -> Y with return type Lazy Y to provide a complete type signature.
| pub method map {X : type} (self : Lazy X) f = | |
| pub method map {X Y : type} (self : Lazy X) (f : X -> Y) : Lazy Y = |
This code is part of a pretty-printer PR #256 . This module have been separated from main PR for easier review and merging.