Skip to content

Commit

Permalink
generate return type
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang committed Sep 20, 2023
1 parent cbeaaef commit 377fdb1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions project/FreeGen2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -429,30 +429,33 @@ class FreeGen2(
val sname = toScalaType(ev.runtimeClass)
val opname = s"${oname}Op"
val ioname = s"${oname}IO"
def kles(retType: String) = s"Kleisli[M, $oname, ${retType}]"
val klesA = kles("A")
val klesUnit = kles("Unit")
val mname = oname.toLowerCase
s"""
| trait ${oname}Interpreter extends ${oname}Op.Visitor[Kleisli[M, $sname, *]] {
|
| // common operations delegate to outer interpreter
| override def raw[A](f: ${sname} => A) = outer.raw(f)
| override def embed[A](e: Embedded[A]) = outer.embed(e)
| override def raiseError[A](e: Throwable) = outer.raiseError(e)
| override def monotonic = outer.monotonic[${sname}]
| override def realTime = outer.realTime[${sname}]
| override def delay[A](thunk: => A) = outer.delay(thunk)
| override def suspend[A](hint: Sync.Type)(thunk: => A) = outer.suspend(hint)(thunk)
| override def canceled = outer.canceled[${sname}]
| override def raw[A](f: ${sname} => A): $klesA = outer.raw(f)
| override def embed[A](e: Embedded[A]): $klesA = outer.embed(e)
| override def raiseError[A](e: Throwable): $klesA = outer.raiseError(e)
| override def monotonic: ${kles("FiniteDuration")} = outer.monotonic[${sname}]
| override def realTime: ${kles("FiniteDuration")} = outer.realTime[${sname}]
| override def delay[A](thunk: => A): $klesA = outer.delay(thunk)
| override def suspend[A](hint: Sync.Type)(thunk: => A): $klesA = outer.suspend(hint)(thunk)
| override def canceled: $klesUnit = outer.canceled[${sname}]
|
| override def performLogging(event: LogEvent) = Kleisli(_ => logHandler.run(event))
| override def performLogging(event: LogEvent): $klesUnit = Kleisli(_ => logHandler.run(event))
|
| // for operations using ${ioname} we must call ourself recursively
| override def handleErrorWith[A](fa: ${ioname}[A])(f: Throwable => ${ioname}[A]) = outer.handleErrorWith(this)(fa)(f)
| override def forceR[A, B](fa: ${ioname}[A])(fb: ${ioname}[B]) = outer.forceR(this)(fa)(fb)
| override def uncancelable[A](body: Poll[${ioname}] => ${ioname}[A]) = outer.uncancelable(this, ${pkg}.${mname}.capturePoll)(body)
| override def poll[A](poll: Any, fa: ${ioname}[A]) = outer.poll(this)(poll, fa)
| override def onCancel[A](fa: ${ioname}[A], fin: ${ioname}[Unit]) = outer.onCancel(this)(fa, fin)
| override def fromFuture[A](fut: ${ioname}[Future[A]]) = outer.fromFuture(this)(fut)
| override def fromFutureCancelable[A](fut: ${ioname}[(Future[A], ${ioname}[Unit])]) = outer.fromFutureCancelable(this)(fut)
| override def handleErrorWith[A](fa: ${ioname}[A])(f: Throwable => ${ioname}[A]): $klesA = outer.handleErrorWith(this)(fa)(f)
| override def forceR[A, B](fa: ${ioname}[A])(fb: ${ioname}[B]): ${kles("B")} = outer.forceR(this)(fa)(fb)
| override def uncancelable[A](body: Poll[${ioname}] => ${ioname}[A]): $klesA = outer.uncancelable(this, ${pkg}.${mname}.capturePoll)(body)
| override def poll[A](poll: Any, fa: ${ioname}[A]): $klesA = outer.poll(this)(poll, fa)
| override def onCancel[A](fa: ${ioname}[A], fin: ${ioname}[Unit]): $klesA = outer.onCancel(this)(fa, fin)
| override def fromFuture[A](fut: ${ioname}[Future[A]]): $klesA = outer.fromFuture(this)(fut)
| override def fromFutureCancelable[A](fut: ${ioname}[(Future[A], ${ioname}[Unit])]): $klesA = outer.fromFutureCancelable(this)(fut)
|
| // domain-specific operations are implemented in terms of `primitive`
|${ctors[A].map(_.kleisliImpl).mkString("\n")}
Expand Down

0 comments on commit 377fdb1

Please sign in to comment.