Skip to content

Instantly share code, notes, and snippets.

@MiloXia
MiloXia / ConditionalCompilation.scala
Last active October 24, 2018 21:36
Scala Conditional Compilation
import scala.language.higherKinds
object Conditions {
//based on: An Introduction to Functional Programming Through Lambda Calculus
trait BOOL {
type body[e1 <: E, e2 <: E, E] <: E //select: (E, E) => E
}
trait TRUE extends BOOL {
type body[e1 <: E, e2 <: E, E] = e1 //true = select_first
}
@MiloXia
MiloXia / PolyFunctor.scala
Created January 23, 2017 10:34
Get Type-Functor of Initial F-algebra in Scala
import scala.language.higherKinds
import shapeless._
import shapeless.ops.coproduct.IsCCons
import shapeless.ops.hlist.IsHCons
object PolyFunctor extends App {
trait TypeFunctor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
def pure[A](a: A): F[A] //for debug & test
@MiloXia
MiloXia / F_Algebra.scala
Created June 21, 2016 02:55
F-algebra & F-coalgebra in Scala
import scala.language.higherKinds
import scalaz._, Scalaz._
object F_Algebra {
//### F-Algebra
//Fixed point of type constructor
case class Fix[F[_]](f: F[Fix[F]])
type Algebra[F[_], A] = Function[F[A], A] //a morphism from F(A) to A