Skip to content

Instantly share code, notes, and snippets.

@clayrat
clayrat / gist:3379950
Created August 17, 2012 15:35
prob-monad-h
module Dist where
import System.Random
data Dist a = Dist {
support :: [a],
gen :: StdGen -> (a, StdGen),
expect :: (a -> Float) -> Float
}
@clayrat
clayrat / gist:3379978
Created August 17, 2012 15:36
prob-monad-sz
import scalaz._
object distribMonad {
import Scalaz._
import scala.util.Random
abstract class Dist[A] {
def support: List[A]
def gen: Random => (A, Random)
case class Global[A](a: A, state: Int) {
def map[B](fun: A => B): Global[B] = Global(fun(a), state)
def flatMap[B](fun: A => Global[B]): Global[B] = fun(a)
override def toString = a.toString + " " + state
}
object Global {
def point[A](a: A): Global[A] = Global(a, 0)
}
case class TupoIO[A](a: A, out: String) {
def map[B](fun: A => B): TupoIO[B] = TupoIO(fun(a), out)
def flatMap[B](fun: A => TupoIO[B]): TupoIO[B] = {
val res = fun(a)
TupoIO(res.a, out + res.out)
}
override def toString = out + a.toString
}
object TupoIO {
case class TupoOI[A](a: A, inputs: Stream[String]) {
def copoint: A = a
def map[B](fun: A => B): TupoOI[B] = TupoOI(fun(a), inputs)
def coflatMap[B](fun: TupoOI[A] => B): TupoOI[B] = {
TupoOI(fun(this), inputs.tail)
}
override def toString = a.toString
}
object comonadTupoOI {
def skipLast[T](s: Stream[T], c: Int): Stream[T] = {
var buf = s take c
s drop c flatMap { x =>
val h = if (!buf.isEmpty)
Stream(buf.head) else Stream()
buf = buf.drop(1) :+ x
h
}
}
import scalaz.stream.nio.{file => nio}
import scodec.bits.ByteVector
...
val uuidSource: Process[Task, String] =
Process.repeatEval(
Task.delay(
// uuid creation
)
import shapeless._
import shapeless.PolyDefns.~>
import shapeless.HList._
object Test {
object size extends (Id ~> Const[Int]#λ) {
def apply[T](t : T) = 1
}
implicit def sizeString = size.λ[String](s => s.length)
import argonaut._, Argonaut._, Shapeless._
object Tool {
trait Enum {
type EnumVal <: Value
protected trait Value { self: EnumVal =>
val name: String
}
}
import scala.concurrent.Await
import scala.concurrent.duration._
import monifu.reactive.Observable
import monifu.concurrent.Scheduler
class Monix {
val s1 = Scheduler.singleThread("test")
val s2 = Scheduler.computation(Runtime.getRuntime.availableProcessors())