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

ambient effects #253

Open
gelisam opened this issue Oct 10, 2024 · 1 comment
Open

ambient effects #253

gelisam opened this issue Oct 10, 2024 · 1 comment
Labels
examples Ideas for cool things to implement in Klister to show off the language

Comments

@gelisam
Copy link
Owner

gelisam commented Oct 10, 2024

One example which should be pretty easy to implement would be a #lang where some of the effects are ambient (like exceptions and spark-level parallelism in Haskell) rather than tracked (like ExceptT and forkIO). It should be possible to take any monad and to make its effect ambient by rewriting #%app to >>=, rewriting (-> Integer Integer) to (-> Integer (MyMonad Integer), etc.

(-> Integer (State S A)) would not need to be rewritten to (-> Integer (StateT S MyMonadT A)), just to (-> Integer (MyMonad (State S A))). That MyMonad represents the fact that ambient effects can occur while calculating which (State S A) action to return. When executing that action, MyAction effects can also be performed... Because when Monad is defined inside that #lang, the user writes that the type of >>= is (-> A (State S B)), but that actually means (-> A (MyMonad (State S B)))! So each time the (strict!) implementation of runState calls that continuation in order to get the next State S B action on which to recur, the MyAction effects occur, interleaved with the state effects as desired.

@gelisam gelisam added the examples Ideas for cool things to implement in Klister to show off the language label Oct 10, 2024
@gelisam
Copy link
Owner Author

gelisam commented Oct 10, 2024

Which effect should the example use? While the effects which would make the most sense to use in the example are exceptions and mutable state, neither of those actually work because

  1. The set of exception types is usually open while ExceptT tracks one specific error type.
  2. Each function usually defines its own local mutable variables, while StateT tracks one single global state. The ST monad would be more appropriate here, but Klister's runtime doesn't support that yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Ideas for cool things to implement in Klister to show off the language
Projects
None yet
Development

No branches or pull requests

1 participant