Skip to content

Instantly share code, notes, and snippets.

import scala.collection.mutable.WrappedArray
abstract class Impl(val name: String) {
val N = 20000
val R = 100
def setup(n: Int): Unit = ()
def run(n: Int): Unit
class JavaEmbeddedRecord<UserId extends Long> {
public UserId getId() {
return (UserId)(new Long(5));
}
}
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
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
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
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 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))
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
@jliszka
jliszka / Examples.scala
Last active December 31, 2015 17:09
Code for "Bayesian models and causality"
/*
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._
from itertools import permutations
import pprint
class Strategy:
def cards(self, cs):
return False
def filter(self, p):
return True