-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share
ComposeNode
definition, provide Parallel
instance between `…
…RecProg` and `RecApProg`.
- Loading branch information
Showing
3 changed files
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package composefree | ||
|
||
import cats.{~>, Applicative, Monad, Parallel} | ||
|
||
sealed trait ComposeNode[M[_], A] | ||
final case class MNode[M[_], A](run: RecProg[M, A]) extends ComposeNode[M, A] | ||
final case class ANode[M[_], A](run: RecApProg[M, A]) extends ComposeNode[M, A] | ||
|
||
object ComposeNode { | ||
implicit def recProgParallel[M[_]]: Parallel.Aux[RecProg[M, *], RecApProg[M, *]] = | ||
new Parallel[RecProg[M, *]] { | ||
type F[a] = RecApProg[M, a] | ||
val applicative = Applicative[RecApProg[M, *]] | ||
val monad = Monad[RecProg[M, *]] | ||
val parallel = new (RecProg[M, *] ~> RecApProg[M, *]) { | ||
def apply[A](p: RecProg[M, A]): RecApProg[M, A] = RecApProg.liftCN(MNode(p)) | ||
} | ||
val sequential = new (RecApProg[M, *] ~> RecProg[M, *]) { | ||
def apply[A](p: RecApProg[M, A]): RecProg[M, A] = RecProg.liftCN(ANode(p)) | ||
} | ||
} | ||
} |