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
// A row vector of Ts, with the number of rows encoded as a type. | |
// Key invariants on methods are encoded through types and witnesses. | |
@tinvariant[R >= 0)] | |
trait RowVectorPhantom[T, R <: XInt] { | |
def apply[I] | |
(implicit i: ValueOf[I]) | |
(implicit iIsPositive: I >= 0, iIsWithinRange: I < R): T | |
def rows(implicit r: ValueOf[R]): Int = r.value | |
} |
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
// Sketches of various meta-encodings of monoids | |
// Naive typeclass trait | |
{ | |
trait Monoid[M] { | |
def zero: M | |
def append(m1: M, m2: M): M | |
} | |
implicit object DoubleSumMonoid extends Monoid[Double] { |
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
import scala.reflect.ClassTag | |
trait MyCollection[T] | |
{ | |
def ping(c2: MyCollection[T]): Unit | |
def pong[C1 <: MyCollection[T] : ClassTag](c1: C1): Unit | |
def pung[C1 <: MyCollection[T], C2 <: MyCollection[T]](c1: C1, c2: C2)(implicit C1: ClassTag[C1], C2: ClassTag[C2]): Unit | |
} | |
class AListyCollection[T] extends MyCollection[T] |
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
/* This models a door. | |
Doors can be opened and closed, and can also be locked and unlocked. | |
However, a door can only be opened and closed when locked, and can only be locked and unlocked when closed. | |
The exercise is to write a fully type-safe, tagless API for this that only exposes legal moves, and where the door, | |
open/closed and locked/unlocked implementations can potentially be freely composed. | |
*/ | |
/* We start with a door. |
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
// build n histograms as (n, histogram) pairs | |
val histograms = for { | |
n <- 1 to N | |
} yield ( | |
n, | |
histogram( | |
dataPoints = for | |
{ | |
t <- (min of time from tradeHistory) to (max of time from tradeHistory - n) | |
} yield price of tradeHistory(t + n) - price of tradeHistory(t) |
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 RequestsManager { | |
case class Start(requests: () => DatabasePublisher[Request]) | |
case class OnError(t: Throwable) | |
case object OnComplete | |
} | |
class RequestsManager() extends Actor with ActorPublisher[Request] { | |
import RequestsManager._ | |
override def receive: Receive = { |
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
trait XsdSimpleTypes { | |
type anySimpleType | |
type string | |
type duration | |
type dateTime | |
type time | |
type date | |
type gYearMonth | |
type gYear |
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
import simulacrum._ | |
import scala.annotation.implicitNotFound | |
@implicitNotFound("Could not find constructor for ${T} that takes a single argument of ${A}") | |
trait Constructor1[+T, -A] { | |
def apply(a: A): T | |
} | |
@implicitNotFound("Could not find destructor for ${T} that decomposes into a single argument of ${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
import javafx.scene.paint.Color | |
import uk.co.turingatemyhamster.gyo._ | |
object Designs { | |
def main(args: Array[String]) { | |
val gfp = Reporter("GFP", Color.GREEN) | |
val gfpCDS = CDS("gfp", gfp) | |
val rfp = Reporter("RFP", Color.RED) |
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
// some types so that we know cardinalities | |
type Optional[T] // 0..1 | |
type Required[T] // 1 | |
type Many[T] // 0..* | |
// a value range restriction | |
type PositiveInteger // x: Int => x > 0 | |
// a whole load of DNA components grouped for whatever reason | |
trait Collection { |