Skip to content

Tutorial: Effect Handlers#20

Merged
forell merged 4 commits intomasterfrom
intro-effect-handlers
Feb 24, 2026
Merged

Tutorial: Effect Handlers#20
forell merged 4 commits intomasterfrom
intro-effect-handlers

Conversation

@ppolesiuk
Copy link
Member

No description provided.

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 comprehensive tutorial on Effect Handlers in Fram, explaining the concept of lexically scoped effect handlers and effect capabilities. The tutorial covers fundamental concepts through progressive examples including exceptions, generators, backtracking, state management, and effect composition.

Changes:

  • Added a complete tutorial document explaining effect handlers from basic concepts to advanced usage
  • Includes multiple code examples demonstrating exceptions, generators, backtracking, state, and effect composition
  • Explains first-class effect handlers, global handlers, type discipline, and effect labels

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return t => Some t
end

## Iterate over all possibilities
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment uses markdown heading syntax ## instead of Fram's comment syntax. According to the Fram syntax shown in the getting-started guide, single-line comments should use #. Change ## Iterate over all possibilities to # Iterate over all possibilities.

Suggested change
## Iterate over all possibilities
# Iterate over all possibilities

Copilot uses AI. Check for mistakes.
}
end

## State handler
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment uses markdown heading syntax ## instead of Fram's comment syntax. According to the Fram syntax shown in the getting-started guide, single-line comments should use #. Change ## State handler to # State handler.

Suggested change
## State handler
# State handler

Copilot uses AI. Check for mistakes.
have seen earlier in this chapter can be defined as follows (with one
additional `hBT_iter` handler that will be needed in the next section).
```fram
## Collect all results into a list
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment uses markdown heading syntax ## instead of Fram's comment syntax. According to the Fram syntax shown in the getting-started guide, single-line comments should use #. Change ## Collect all results into a list to # Collect all results into a list.

Suggested change
## Collect all results into a list
# Collect all results into a list

Copilot uses AI. Check for mistakes.
return t => [t]
end

## Return the first successful result (if any)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment uses markdown heading syntax ## instead of Fram's comment syntax. According to the Fram syntax shown in the getting-started guide, single-line comments should use #. Change ## Return the first successful result (if any) to # Return the first successful result (if any).

Suggested change
## Return the first successful result (if any)
# Return the first successful result (if any)

Copilot uses AI. Check for mistakes.
Copy link
Member

@forell forell left a comment

Choose a reason for hiding this comment

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

The examples are well-chosen and the sections are presented in a good order. I think the explanation gets a bit messy when resumptions are first introduced, but if you prefer you can leave it alone for now and merge as-is, because the ultimate benchmark is how newcomers to Fram react to this tutorial anyway.

Comment on lines +195 to +196
implementation of the `yield` operation we explicitly name the resumption
(a function that resumes the computation) as `r`, and use it in the body.
Copy link
Member

Choose a reason for hiding this comment

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

The word resumption is used earlier, so perhaps it's a bit unexpected to first define it here.

Comment on lines +174 to +178
handlers*, meaning that the resumption contains the entire handler, so any
subsequent effects raised during the resumed computation will be interpreted
within the call to `resume`. In this case, it means that values yielded
during the resumed computation will also be handled by the same `yield`
handler but they will be placed after `x` in the resulting list.
Copy link
Member

Choose a reason for hiding this comment

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

I get that this is trying to be precise, but I fear this might make it more confusing to someone not familiar with effect handers, and uses the word resumption before it's defined in a later paragraph. Perhaps it could be shortened to something like "Fram implements so-called deep handlers, which means that subsequent uses of yield will be handled by the same handler and placed after x in the resulting list."

@forell forell merged commit 57ebf5e into master Feb 24, 2026
@forell forell deleted the intro-effect-handlers branch February 24, 2026 15:02
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.

3 participants