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 util.continuations._ | |
| import scalaz._ | |
| import Scalaz._ | |
| def reify[M[_] : Monad, A](body: => A @cps[M[A]]): M[A] = | |
| reset{val result: A = body; implicitly[Monad[M]].pure[A](result)} | |
| implicit def monad2reflect[M[_] : Monad, A](action: M[A]) = new { | |
| def reflect[B]: A @cps[M[B]] = | |
| shift{(k: A => M[B]) => implicitly[Monad[M]].bind(action, k)} |
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 scalaz.Scalaz._ | |
| import scalaz.Order._ | |
| import util.control.Exception.allCatch | |
| val RE = """(\d+)|([^\d]+)""".r | |
| def s2i(s: String): Iterable[Either[String, Int]] = | |
| RE.findAllIn(s).map{ s => | |
| allCatch.either(s.toInt).left.map(_ => s) | |
| }.++(Iterator(Left("dummy"))).toIterable |
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 Nat { | |
| type IsZero <: Bool | |
| type Prev <: Nat | |
| type Divisable[A <: Nat] = DivisableImpl[A, A] | |
| type DivisableImpl[A <: Nat, B <: Nat] <: Bool | |
| } | |
| trait Z extends Nat { | |
| type IsZero = True | |
| type Prev = Nothing |
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 math.{pow, log, sqrt} | |
| import java.util.Random | |
| import org.apache.commons.math.stat.StatUtils.mean | |
| import org.apache.commons.math.stat.regression.SimpleRegression | |
| object HurstExponent extends App { | |
| def hurstExponent(xs: Array[Double]): Double = { | |
| def S(xs: Array[Double]): Double = { | |
| val meanXs = mean(xs) |
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 scalaz.Forall | |
| case class Record(x : List[Int], y : List[Double]) | |
| def lift( | |
| f: Forall[({type X[A] = (List[A], List[A]) => List[A]})#X], | |
| a: Record, | |
| b: Record | |
| ): Record = | |
| (a, b) match { |
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
| (defun %walker (code test result &optional (cons-fn #'cons)) | |
| (labels ((iter (code) | |
| (if (consp code) | |
| (if (and (consp (car code)) (funcall test (car code))) | |
| (funcall cons-fn | |
| (funcall result (car code)) | |
| (iter (cdr code))) | |
| (cons | |
| (iter (car code)) | |
| (iter (cdr code)))) |
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
| function callcc(f) { | |
| return f(new Continuation()); | |
| } | |
| importPackage(java.util); | |
| var metaCont = new java.util.Stack(); | |
| function abort(thunk) { | |
| return metaCont.peek()(thunk()); |
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
| (ql:quickload :pipes) | |
| (ql:quickload :cl-cont) | |
| (ql:quickload :cl-monad-macros) | |
| (defpackage :llmonad | |
| (:use :cl :pipes :cl-cont :cl-monad-macros)) | |
| (in-package :llmonad) | |
| (defun pipe-tail-no-cache (pipe) |
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
| (use 'delimc.core) | |
| (use 'clojure.contrib.monads) | |
| (defmacro reify [thunk] | |
| `(reset | |
| (m-result ~thunk))) | |
| (defmacro reflect [meaning] | |
| `(shift k# | |
| (m-bind ~meaning k#))) |
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
| (ql:quickload :cl-cont) | |
| (ql:quickload :alexandria) | |
| (ql:quickload :fare-matcher) | |
| (defpackage :reify-reflect | |
| (:use :cl :cl-cont :fare-matcher :fare-matcher-extensions) | |
| (:import-from :alexandria :iota)) | |
| (in-package :reify-reflect) |