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
{-# LANGUAGE RankNTypes #-} | |
module CPS where | |
import Control.Applicative | |
newtype StateCPS s a = StateCPS { runStateCPS :: forall r. s -> (a -> s -> r) -> r } | |
instance Functor (StateCPS s) where | |
fmap f (StateCPS k) = StateCPS $ \s c -> k s (c . f) |
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
package gist | |
import scalaz._ | |
import scalaz.std.string._ | |
import scalaz.syntax.listenableMonadWriter._ | |
object MonadWriterExample extends App { | |
implicit val monadWriter = EitherT.listenableMonadWriter[Writer, String, String] | |
case class Person(firstName: String, age: Int) |
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
def incr(i: Int): EvanderProcess[Int] = (i + 1).pure[EvanderProcess] | |
def apply_n(events: List[Event]): EvanderProcess[List[Event]] = { | |
val sorted = events sortBy (_.v) | |
val received = sorted map (_.v) | |
def msg(expected: Int, got: Int, version: Int) = | |
"Event %d expected, but got %d instead (in events %s from version %d)".format(expected, got, received mkString ", ", version) | |
for { |
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
object Toto { | |
case class SummaryRow(msg: String, count: Int, rate: Float) | |
case class BreakDownRow(sup: String, amount: Int) | |
case class SegmentedRow(segment: String, length: Int) | |
type Id[A] = A | |
trait Reporting[A, B[_]] { | |
val parser: Parser[A] |
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
def foo[F[_], A](xs: F[A], f: A => String)(implicit F: Foldable[F], P: Pure[F], M: Monoid[F[A]]): Map[String, F[A]] = { | |
F.foldMap[A, Map[String, F[A]]](xs, a => Map(f(a) -> F.pure(a))) | |
} | |
foo[List, BreakDownRow](xs: List[BreakDownRow])(f: BreakDownRow => String): Map[String, List[BreakDownRow]] | |
foo[Id, SummaryRow](xs: Id[SummaryRow])(f: SummaryRow => String): Map[String, Id[SummaryRow]] | |
bar[A <: Json, B <: Json](l: Map[String, A], r: Map[String, B]): Map[String, Json] |
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
{-# LANGUAGE RankNTypes #-} | |
module Fun where | |
import Data.Monoid | |
-- Warm up | |
-- negate 1 = -1 | |
negateCPS :: Int -> (Int -> r) -> r |
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
object ex { | |
def ana[A, B](start: B)(f: B => Option[(A, B)]): List[A] = f(start) match { | |
case Some((a, b)) => a :: ana(b)(f) | |
case _ => Nil | |
} | |
def cartesian[A](xss: List[List[A]]): List[List[(A, A)]] = ana(xss) { | |
case xs :: vs :: rest => | |
val action = for { | |
x <- 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
[error] (run-main) java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.Nothing$ | |
java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.Nothing$ | |
at fr.applicius.kyub.control.stream.Streamer$$anonfun$echo$1.apply(Streamer.scala:108) | |
at fr.applicius.kyub.control.stream.Streamer$$anonfun$1.apply(Streamer.scala:102) | |
at fr.applicius.kyub.control.stream.Streamer$$anonfun$1.apply(Streamer.scala:101) | |
at fr.applicius.kyub.control.stream.Step$Return.flatMap(Streamer.scala:71) | |
at fr.applicius.kyub.control.stream.Step$Await$$anonfun$flatMap$1.apply(Streamer.scala:76) | |
at fr.applicius.kyub.control.stream.Step$Await$$anonfun$flatMap$1.apply(Streamer.scala:76) | |
at fr.applicius.kyub.control.stream.Step$Await$$anonfun$flatMap$1.apply(Streamer.scala:76) | |
at fr.applicius.kyub.control.stream.Step$Await$$anonfun$flatMap$1.apply(Streamer.scala:76) |
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 com.clarifi.machines._ | |
import play.api.libs.iteratee.{ Enumerator, Input, Iteratee } | |
import play.api.libs.concurrent.Execution.Implicits._ | |
import scala.concurrent.Future | |
def simple[K, E](machine: Machine[K, E]): Enumerator[E] = new Enumerator[E] { | |
def apply[A](start: Iteratee[E, A]): Future[Iteratee[E, A]] = | |
val result = machine.foldLeft(Future.successful(start)) { (future, value) ⇒ |
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
package deiko | |
import java.nio.charset.Charset | |
import java.util.concurrent.CancellationException | |
import org.jboss.netty.buffer.ChannelBuffers | |
import org.jboss.netty.channel.{ Channel, ChannelFuture, ChannelFutureListener } | |
import org.jboss.netty.handler.codec.http.{ DefaultHttpChunk, HttpChunk } | |
import scalaz.stream.{ Process, process1, processes } | |
import scalaz.concurrent.Task | |
import Process.{ Process1, Sink } |