-
Notifications
You must be signed in to change notification settings - Fork 11
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
ToyIO demonstration of a basic IO implementation for runtimes #1162
base: main
Are you sure you want to change the base?
Conversation
/** | ||
* fix(f) = f(fix(f)) | ||
*/ | ||
case class ApplyFix[E, A, B](arg: A, fixed: (A => ToyIO[E, B]) => (A => ToyIO[E, B])) extends ToyIO[E, B] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this constructor can't be written in Bosatsu because ToyIO[E, B]
is in an invariant position (contravariant and covariant in the fixed function, and we can only have co-variant recursion in bosatsu. But we could define this constructor outside of bosatsu and return it via an external def
.
def run[E, A](io: ToyIO[E, A]): Either[E, A] = { | ||
|
||
@annotation.tailrec | ||
def loop[E1, A1](arg: ToyIO[E1, A1], stack: Stack[E1, A1, E, A]): Either[E, A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loop is the only place with explicit recursion. This loop would be implemented in the runtime or host language using a loop to avoid blowing the stack.
@@ -183,8 +183,8 @@ lazy val core = | |||
// periodically we use acyclic to ban cyclic dependencies and make compilation faster | |||
, | |||
autoCompilerPlugins := true, | |||
addCompilerPlugin("com.lihaoyi" % "acyclic_2.13.12" % "0.3.11"), | |||
scalacOptions += "-P:acyclic:force" | |||
//addCompilerPlugin("com.lihaoyi" % "acyclic_2.13.12" % "0.3.11"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented this because it blows up the repl
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1162 +/- ##
==========================================
+ Coverage 91.32% 91.41% +0.08%
==========================================
Files 96 97 +1
Lines 11846 11898 +52
Branches 2675 2727 +52
==========================================
+ Hits 10818 10876 +58
+ Misses 1028 1022 -6 ☔ View full report in Codecov by Sentry. |
The idea here is to encode general recursion into a data structure, then have the recursive loop be implemented in the runtime or host language.