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

["Request"] Algebraic Effects #155

Open
tapegram opened this issue Oct 27, 2021 · 2 comments
Open

["Request"] Algebraic Effects #155

tapegram opened this issue Oct 27, 2021 · 2 comments

Comments

@tapegram
Copy link

tapegram commented Oct 27, 2021

What version are you currently using?
1.0.0

What would you like to see?
An Effect system similar like Frank, Unison Abilities, or Freer monads.

@raulraja and @nomisRev gave additional context in the slack thread about this.

I would like to be able to create custom "Capabilities" or Effects if possible, but in general, the kind of standards like Writer, State, etc. would Immediately be useful. Most of my real-life use cases are Logging, Save/Fetching from a data store, or making a query to an external api.

Thank you!

@nomisRev
Copy link
Member

nomisRev commented Apr 5, 2023

Hey @tapegram,

I think this is quite easily possible with the new encodings, and context receivers. Although context receivers are only partially released. Perhaps we can write an additional document around this in the new website, I don't think this requires any new code or changes inside Arrow. So moving this to the arrow-website repo.

We could consider introducing a new module, or separate library (repo) to expose some bases interfaces / implementations later on if needed.

I.e. I think for State context(Atomic<State>) is probably sufficient, and that'd be safe in concurrent environments and everything. Writer is probably just a context(Atomic<List<String>>), or a super tiny wrapper around it that combines W with (W, W) -> W.

@JvmInline
value class MyWriter(private val atom: Atomic<MyValue>) {
  fun write(value: MyValue): Unit = atom.update { current -> current + value }
  fun get(): MyValue = atom.value
}

typealias RandomState = Atomic<SEED>(INITIAL_SEED)

context(RandomState, MyWriter, Raise<Error>)
fun myProgram(): Int {
  ...
}

cc\ @serras

@nomisRev nomisRev transferred this issue from arrow-kt/arrow Apr 5, 2023
@serras
Copy link
Member

serras commented Apr 5, 2023

In theory this information should be present in the Effects and contexts section of the website.

@tapegram don't hesitate to let us know if you think that page could be improved, or any concept made more clear.

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

No branches or pull requests

3 participants