This file contains hidden or 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
| object monadicOA { | |
| type ??? = Any | |
| trait Monad[M[+_]] { | |
| def unit[A]: A => M[A] | |
| def bind[A, B]: M[A] => (A => M[B]) => M[B] | |
| def map[A, B]: M[A] => (A => B) => M[B] | |
| } | |
| object Monad { |
This file contains hidden or 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
| object monadicOA { | |
| type ??? = Any | |
| trait Monad[M[+_]] { | |
| def unit[A]: A => M[A] | |
| def bind[A, B]: M[A] => (A => M[B]) => M[B] | |
| def map[A, B]: M[A] => (A => B) => M[B] | |
| } | |
| object Monad { |
This file contains hidden or 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
| object tl_church { | |
| trait Booleans { | |
| type Bool <: { type Not <: Bool } | |
| type True <: Bool | |
| type False <: Bool | |
| } | |
| trait Nats { | |
| type Nat |
This file contains hidden or 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
| sealed trait Nat | |
| trait Succ[T <: Nat] <: Nat | |
| trait Zero <: Nat | |
| sealed trait Bool { type Not <: Bool } | |
| trait True <: Bool { type Not = False } | |
| trait False <: Bool { type Not = True } | |
| trait Foldable[Base] { |
This file contains hidden or 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
| package object stateful { | |
| import scala.collection.mutable | |
| trait Stateful { | |
| private val cache = mutable.HashMap.empty[Int, Any] | |
| // TODO use some reasonable HashMap implementation here | |
| // TODO how slow is the reflection here, perform microbenchmarks? | |
| protected[stateful] def getStateOrElseUpdate(d: Decorate[_])(s: => d.State): d.State = |
This file contains hidden or 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
| // Default functor and monad TCs | |
| trait Functor[F[_]] { | |
| def map[A, B](fa: F[A], f: A => B): F[B] | |
| } | |
| trait Monad[M[_]] { | |
| def unit[A](value: A): M[A] | |
| def flatMap[A, B](ma: M[A], f: A => M[B]): M[B] | |
| def map[A, B](ma: M[A], f: A => B): M[B] = flatMap(ma, f andThen unit) | |
| } |
This file contains hidden or 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
| object freer { | |
| trait Functor[F[_]] { | |
| def map[A, B](fa: F[A], f: A => B): F[B] | |
| } | |
| object Functor { | |
| @inline | |
| def apply[F[_]](implicit f: Functor[F]): Functor[F] = f | |
| implicit class FunctorOps[A, F[_]: Functor](fa: F[A]) { |
This file contains hidden or 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
| scalaVersion := "2.11.7" | |
| // For this dependency you have to clone | |
| // https://github.com/b-studios/MixinComposition | |
| // and run `sbt publishLocal` | |
| libraryDependencies += "de.unimarburg" % "mixin-composition_2.11" % "0.2-SNAPSHOT" | |
| libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value | |
| libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.6" |
This file contains hidden or 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
| // Finds a R in an T | |
| trait Select[T, R] { | |
| def apply(t: T): R | |
| } | |
| trait LowPrio { | |
| implicit def autoLeft[T, R, O]: Select[(R, O), R] = ??? | |
| } | |
| object Select extends LowPrio { | |
| implicit def autoRight[T, R, O]: Select[(O, R), R] = ??? |
This file contains hidden or 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
| // Finds a R in an T | |
| trait Select[T, R] { | |
| def apply(t: T): R | |
| } | |
| trait LowPrio { | |
| def apply[T, R](f: T => R): Select[T, R] = new Select[T, R] { | |
| def apply(t: T): R = f(t) | |
| } | |
| implicit def autoLeft[T, R, O]: Select[(R, O), R] = Select(_._1) |