Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicize Free#foldStep #3225

Merged
merged 1 commit into from
Dec 31, 2019
Merged

Conversation

djspiewak
Copy link
Member

@djspiewak djspiewak commented Dec 23, 2019

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 at List was foldLeft: 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 a List[A] into a List[(A, A)] such that all adjacent even/odd values are paired together (i.e. index 0 with index 2, 1 with 3 and so on). Doing this with a foldLeft is possible, but hard (well, at least annoying). The analogous transformation on Free is exponentially more difficult with foldMap, 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 with foldMap 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 for Free, yielding at each suspension point, making it possible to write fully pure Fiber implementations which still exhibit parallel semantics.

@codecov-io
Copy link

Codecov Report

Merging #3225 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3225   +/-   ##
=======================================
  Coverage   93.05%   93.05%           
=======================================
  Files         376      376           
  Lines        7412     7412           
  Branches      200      192    -8     
=======================================
  Hits         6897     6897           
  Misses        515      515
Flag Coverage Δ
#scala_version_212 93.36% <ø> (-0.02%) ⬇️
#scala_version_213 92.82% <ø> (ø) ⬆️
Impacted Files Coverage Δ
free/src/main/scala/cats/free/Free.scala 92.1% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 424f10a...e814bf7. Read the comment docs.

@travisbrown travisbrown self-requested a review December 30, 2019 20:21
Copy link
Contributor

@travisbrown travisbrown left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

@djspiewak djspiewak merged commit 371fe73 into typelevel:master Dec 31, 2019
@travisbrown travisbrown added this to the 2.2.0-M1 milestone Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants