Skip to content

First-class lazy evaluation#264

Merged
ppolesiuk merged 2 commits intofram-lang:masterfrom
wojpok:first-class-lazy-values
Nov 3, 2025
Merged

First-class lazy evaluation#264
ppolesiuk merged 2 commits intofram-lang:masterfrom
wojpok:first-class-lazy-values

Conversation

@wojpok
Copy link
Collaborator

@wojpok wojpok commented Nov 3, 2025

This code is part of a pretty-printer PR #256 . This module have been separated from main PR for easier review and merging.

Copy link
Member

@ppolesiuk ppolesiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ppolesiuk ppolesiuk requested a review from Copilot November 3, 2025 18:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Lazy module 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.

@wojpok wojpok requested a review from ppolesiuk November 3, 2025 19:42
Copy link
Member

@ppolesiuk ppolesiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, the PR is ready for merging. Thanks!

@ppolesiuk ppolesiuk requested a review from Copilot November 3, 2025 20:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pub method map {X : type} (self : Lazy X) f =
pub method map {X Y : type} (self : Lazy X) (f : X -> Y) : Lazy Y =

Copilot uses AI. Check for mistakes.
end

{## Creates new lazy value with mapped results. ##}
pub method map {X : type} (self : Lazy X) f =
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pub method map {X : type} (self : Lazy X) f =
pub method map {X Y : type} (self : Lazy X) (f : X -> Y) : Lazy Y =

Copilot uses AI. Check for mistakes.
@ppolesiuk ppolesiuk merged commit fc46491 into fram-lang:master Nov 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants