Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to the fact that the algebra itself is private, it is not currently possible to implement custom interpreters on top of
Free
. A first-order analogue for this limitation would be as if the only way to look atList
wasfoldLeft
: it's great, and technically can do anything, but it's immensely difficult to do things that are more complicated than a simple traversal. For example, imagine I want to convert aList[A]
into aList[(A, A)]
such that all adjacent even/odd values are paired together (i.e. index0
with index2
,1
with3
and so on). Doing this with afoldLeft
is possible, but hard (well, at least annoying). The analogous transformation onFree
is exponentially more difficult withfoldMap
, and also impossible to type check (due to the existentials involved).foldStep
breaks down this restriction by giving safe, direct access to the internals of the data structure, enabling much more complex interpreters than what are currently possible withfoldMap
alone. My current practical example of this need comes from the ongoing Cats Effect 3 development, where I have implemented an interpreter which has cooperative parallelism semantics forFree
, yielding at each suspension point, making it possible to write fully pureFiber
implementations which still exhibit parallel semantics.