Skip to content

Instantly share code, notes, and snippets.

class Poly(coeffs: Int => Double) {
// Memoizing coefficient accessor. Returns the coefficient for x^n.
def apply(n: Int): Double = memo.getOrElseUpdate(n, this.coeffs(n))
// The memo table
private val memo = scala.collection.mutable.HashMap[Int, Double]()
def +(that: Poly): Poly = new Poly(n => this(n) + that(n))
abstract class Dual(val rank: Int) {
self =>
// Cell value accessor
protected def get(r: Int, c: Int): Double
// Memoizing cell value accessor
def apply(r: Int, c: Int): Double = memo.getOrElseUpdate(r - c, self.get(r, c))
// The memo table
object Injection {
// A table of constant 0 functions
def zeroes: Int => (Int => Int) = (n1: Int) => (n2: Int) => 0
// Update an entry in a function table with a new function at the given position.
def update(t: Int => (Int => Int), k: Int, f: Int => Int): Int => (Int => Int) = {
(n: Int) => if (n == k) f else t(n)
}
def diag(hinv: Int => (Int => Int)): Int => Int = {
class !<:<[A, B]
implicit def any[A, B]: A !<:< B = new !<:<[A, B]
implicit def sub1[A, B >: A]: A !<:< B = new !<:<[A, B]
implicit def sub2[A, B >: A]: A !<:< B = new !<:<[A, B]
sealed trait ShardKeyNotSpecified
sealed trait ShardAware
trait Sharded
sealed trait Limited
sealed trait Unlimited
sealed trait Lim extends Limited with Unlimited
sealed trait Skipped
sealed trait Unskipped
sealed trait Sk extends Skipped with Unskipped
sealed trait Selected
sealed trait Unselected
@jliszka
jliszka / gist:2880013
Created June 6, 2012 04:55
Multiple phantom types in a single type parameter
object test {
sealed trait Limited
sealed trait Unlimited
sealed trait Lim extends Limited with Unlimited
sealed trait Skipped
sealed trait Unskipped
sealed trait Sk extends Skipped with Unskipped
class !<:<[A, B]
implicit def any[A, B]: A !<:< B = new !<:<[A, B]
implicit def sub1[A, B >: A]: A !<:< B = new !<:<[A, B]
implicit def sub2[A, B >: A]: A !<:< B = new !<:<[A, B]
abstract class Tag
abstract class Unlimited
abstract class Unselected
abstract class Unskipped