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 Trampolines { | |
def odd[A](as: List[A]): TailRec[Boolean] = | |
as match { | |
case Nil => Return(false) | |
case _ :: xs => Suspend(() => even(xs)) | |
} | |
def even[A](as: List[A]) = as match { | |
case Nil => Return(true) | |
case _ :: xs => Suspend(() => odd(xs)) |
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 scalaz._ | |
import \/._ | |
import Free._ | |
import scalaz.syntax.monad._ | |
import java.util.concurrent.atomic.AtomicReference | |
import java.util.concurrent.CountDownLatch | |
object Experiment { | |
sealed trait OI[A] { | |
def map[B](f: A => B): OI[B] |
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
package scalaz | |
import scalaz.{State => _, _} | |
import scalaz.Free.FreeC | |
import scalaz.Id.Id | |
import FreeState.StateF | |
sealed abstract class FreeState[S, A] { | |
def map[B](f: A => B): FreeState[S, B] | |
} |
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
{-# LANGUAGE RankNTypes #-} | |
import Prelude hiding (readFile) | |
import qualified Prelude as P | |
data Free f a = | |
Done a | |
| More (f (Free f a)) | |
instance Functor f => Functor (Free f) 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
-- Type-aligned sequence catenable queue supporting O(1) append, snoc, uncons | |
-- Don't need it to be a dequeue (unsnoc not needed) | |
data TCQueue c a b -- c is the category, a is starting type, b is ending type | |
type Channel f a b = TCQueue (Transition f) a b | |
type Process f b = Channel f () b | |
data Transition f a b where | |
Bind :: (a -> Process f b) -> Transition f a b | |
OnHalt :: (Cause -> Process f b) -> Transition f a b |
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
{-# OPTIONS_GHC -Wall #-} | |
module NatStream where | |
data Nat = Zero | Succ Nat | |
data Stream a = a :< Stream a | |
-- Stream is the trie induced by Nat. | |
-- Here's the isomorphism, explicitly: |
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
package nlist | |
sealed trait Nat | |
sealed trait Z extends Nat | |
sealed trait S[A <: Nat] extends Nat | |
sealed trait NList[A <: Nat, +B] { | |
type Length = A | |
def zap[C](l: NList[Length, B => C]): NList[Length, C] |
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 BenchmarkCommon { | |
import scala.util.Random | |
val DatasetSize = 10000 | |
val Iterations = 10000 | |
val ArrayPoolSize = 1000 | |
val ArrayPool = { | |
def randomArray(): Array[Int] = { | |
val array = new Array[Int](DatasetSize) | |
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 scalaz._, Scalaz._, NonEmptyList._ | |
sealed trait Interval[+A] { | |
val min: A | |
val max: A | |
def map[B: Order](f: A => B): Interval[B] = | |
Interval(f(min), f(max)) | |
def merge[AA >: A](i: Interval[AA])(implicit E: Enum[AA]): Option[Interval[AA]] = |
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 scala.language.higherKinds | |
import scala.language.implicitConversions | |
import scala.language.reflectiveCalls | |
trait Forall[M[_]] { | |
def apply[A]: M[A] | |
} | |
object Maybe { |
OlderNewer