Skip to content

Instantly share code, notes, and snippets.

Created June 2, 2016 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0f788993b925f91805552ccc0acf435e to your computer and use it in GitHub Desktop.
Save anonymous/0f788993b925f91805552ccc0acf435e to your computer and use it in GitHub Desktop.
the description for this gist
object Logo{
sealed trait Instruction[A]
...
sealed trait PencilInstruction[A]
...
case class Position(x: Double = 0, y: Double = 0, heading: Degree = Degree())
case class Degree(private val d: Int = 0) {...}
object dsl {
class Moves[F[_]](implicit I: Inject[Instruction, F]) {
def forward(pos: Position, l: Int): Free[F, Position] = Free.inject[Instruction, F](Forward(pos, l))
def backward(pos: Position, l: Int): Free[F, Position] = Free.inject[Instruction, F](Backward(pos, l))
def left(pos: Position, degree: Degree): Free[F, Position] = Free.inject[Instruction, F](RotateLeft(pos, degree))
def right(pos: Position, degree: Degree): Free[F, Position] = Free.inject[Instruction, F](RotateRight(pos, degree))
def showPosition(pos: Position): Free[F, Unit] = Free.inject[Instruction, F](ShowPosition(pos))
}
object Moves {
implicit def moves[F[_]](implicit I: Inject[Instruction, F]): Moves[F] = new Moves[F]
}
class PencilActions[F[_]](implicit I: Inject[PencilInstruction, F]) {
def pencilUp(pos: Position): Free[F, Unit] = Free.inject[PencilInstruction, F](PencilUp(pos))
def pencilDown(pos: Position): Free[F, Unit] = Free.inject[PencilInstruction, F](PencilDown(pos))
}
object PencilActions {
implicit def pencilActions[F[_]](implicit I: Inject[PencilInstruction, F]): PencilActions[F] = new PencilActions[F]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment