Skip to content

Instantly share code, notes, and snippets.

View b-studios's full-sized avatar

Jonathan Immanuel Brachthäuser b-studios

View GitHub Profile
@b-studios
b-studios / build.sbt
Last active December 14, 2016 15:09
New encoding for extensible objects
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"
@b-studios
b-studios / FreerMonads.scala
Created September 20, 2016 16:46
A straightforward translation of "Freer Monads, More Extensible Effects" to Scala
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]) {
@b-studios
b-studios / TypeConstructor.scala
Created September 20, 2016 10:18
Trying to help the compiler inferring type constructors
// 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)
}
@b-studios
b-studios / stateful-pimp.scala
Created August 2, 2016 16:13
Nanolibrary for a stateful pimp-my-library pattern.
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 =
@b-studios
b-studios / TLFoldable.scala
Last active July 31, 2016 18:58
Experiments with type-level foldables
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] {
@b-studios
b-studios / TLChurch.scala
Last active July 31, 2016 19:52
Simple example of type-level church encoding
object tl_church {
trait Booleans {
type Bool <: { type Not <: Bool }
type True <: Bool
type False <: Bool
}
trait Nats {
type Nat
@b-studios
b-studios / monadic-oa.scala
Created June 8, 2016 13:19
Some experiments with monadic object algebras
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 {
@b-studios
b-studios / monadic-oa.scala
Created June 8, 2016 13:19
Some experiments with monadic object algebras
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 {
@b-studios
b-studios / object-encodings.scala
Created June 3, 2016 14:50
Comparing Object Encodings
/**
* This file contains some notes taken while reading:
*
* Comparing Object Encodings
* Kim B. Bruce, Luca Cardelli and Benjamin C. Pierce
*/
package object encodings {
// Library Stuff
trait Fix[F[_]] {
(00.000084) Added /sys/fs/cgroup/cpuset:/sys/fs/cgroup/cpuset ext mount mapping
(00.000136) Added /sys/fs/cgroup/cpu:/sys/fs/cgroup/cpu ext mount mapping
(00.000143) Added /sys/fs/cgroup/cpuacct:/sys/fs/cgroup/cpuacct ext mount mapping
(00.000149) Added /sys/fs/cgroup/memory:/sys/fs/cgroup/memory ext mount mapping
(00.000155) Added /sys/fs/cgroup/devices:/sys/fs/cgroup/devices ext mount mapping
(00.000172) Added /sys/fs/cgroup/freezer:/sys/fs/cgroup/freezer ext mount mapping
(00.000178) Added /sys/fs/cgroup/blkio:/sys/fs/cgroup/blkio ext mount mapping
(00.000184) Added /sys/fs/cgroup/perf_event:/sys/fs/cgroup/perf_event ext mount mapping
(00.000200) Added /sys/fs/cgroup/hugetlb:/sys/fs/cgroup/hugetlb ext mount mapping
(00.000206) Added /sys/fs/cgroup/systemd:/sys/fs/cgroup/systemd ext mount mapping