-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix annotations being passed from trait to generated companion
- Loading branch information
Showing
7 changed files
with
74 additions
and
65 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
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,44 @@ | ||
package readme | ||
|
||
import diesel._, cats._, cats.implicits._ | ||
|
||
object DieselDemo { | ||
|
||
// Declare your DSL | ||
@diesel | ||
trait Maths[F[_]] { | ||
def times(l: Int, r: Int): F[Int] | ||
def add(l: Int, r: Int): F[Int] | ||
} | ||
|
||
@diesel | ||
trait Logger[F[_]] { | ||
def info(s: String): F[Unit] | ||
} | ||
|
||
// Import companion-to-interpreter aliasing sugar | ||
import Maths.ops._, Logger.ops._ | ||
def prog[F[_]: Monad: Maths: Logger](x: Int, y: Int): F[Int] = { | ||
for { | ||
p <- Maths.times(x, y) | ||
_ <- Logger.info(s"Product: $p") | ||
s <- Maths.add(x, y) | ||
_ <- Logger.info(s"Sum: $s") | ||
} yield p + s | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
// Wire in our interpreters | ||
implicit val mathsInterp = new Maths[Id] { | ||
def times(l: Int, r: Int) = l * r | ||
def add(l: Int, r: Int) = l + r | ||
} | ||
implicit val loggingInterp = new Logger[Id] { | ||
def info(msg: String) = println(msg) | ||
} | ||
|
||
val _ = prog[Id](1, 2) | ||
} | ||
|
||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.