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 NoImplicitPrelude #-} | |
module Origami where | |
import Prelude | |
( | |
(.) | |
, (-) | |
, (*) | |
, (++) | |
, ($) |
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
sealed trait Free[F[_], A] | |
case class Return[F[_], A](v: A) extends Free[F, A] | |
case class Suspend[F[_], A](s: F[Free[F, A]]) extends Free[F, A] | |
sealed trait ProcessB[T[_], O, B] | |
case class Emit[T[_], O, B](o: O, next: B) extends ProcessB[T, O, B] | |
case class Await[T[_], A, O, B](ta: T[A], k: A => B) extends ProcessB[T, O, B] | |
case class Stop[T[_], O, B] extends ProcessB[T, O, B] | |
type Process[T[_], O] = Free[({ type F[x] = ProcessB[T,O,x] })#F, O] |
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 scala.language.higherKinds | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
object Functor { | |
def apply[F[_], A, B](fa: F[A])(f: A => B)(implicit F: Functor[F]): F[B] = | |
F.map(fa)(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
ghc -Wall -ferror-spans -fforce-recomp -c /home/yorick/Desktop/process.hs | |
/home/yorick/Desktop/process.hs:34:9-34: | |
Couldn't match type `a1' with `a2' | |
because type variable `a2' would escape its scope | |
This (rigid, skolem) type variable is bound by | |
a type expected by the context: | |
m a2 -> (a2 -> Process m a) -> Process m a -> r | |
The following variables have types that mention a1 | |
awaiting :: m a1 -> (a1 -> Process m a) -> Process m a -> 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
{-# LANGUAGE RankNTypes #-} | |
type Foo = forall m. Monad m => Int -> m Int | |
data Free f a = Pure a | |
| Free (f (Free f a)) | |
data Instr a = Instr Int a | |
instance Functor Instr where |
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 scala.concurrent.Future | |
import scala.concurrent.duration.Duration | |
import scalaz.concurrent.Task | |
import scalaz.stream._ | |
import play.api.libs.iteratee._ | |
import Process._ | |
object Conversion { |
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 } |
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
[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
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 |