This file contains 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
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 |
This file contains 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 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 |
This file contains 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 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 |
This file contains 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
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 |
This file contains 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 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 = { |
This file contains 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
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 |
This file contains 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
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)) |
This file contains 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 Data.List | |
import Test.QuickCheck | |
import qualified Data.Map as Map | |
nats = [1..] | |
divides a b = b `mod` a == 0 | |
sieve (n:t) m = case Map.lookup n m of | |
Nothing -> n : sieve t (Map.insert (n*n) [n] m) | |
Just ps -> sieve t (foldl reinsert (Map.delete n m) ps) | |
where |
This file contains 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 Data.List | |
import Test.QuickCheck | |
import qualified Data.Map as Map | |
nats = [1..] | |
divides a b = b `mod` a == 0 | |
sieve (n:t) m = case Map.lookup n m of | |
Nothing -> n : sieve t (Map.insert (n*n) [n] m) | |
Just ps -> sieve t (foldl reinsert (Map.delete n m) ps) | |
where |
This file contains 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
/* | |
Setup: | |
$ git clone https://github.com/jliszka/probability-monad.git | |
$ cd probability-monad | |
$ ./sbt console | |
scala> :load Examples.scala | |
*/ | |
import probability_monad._ | |
import probability_monad.Distribution._ |
OlderNewer