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 fpinscala.streamingio | |
/** | |
Machine takes binary type constructor now. | |
Requests are an F[X,Y] and an X, for some X and Y. | |
*/ | |
trait Machine[F[_,_],A] { | |
def vary[F0[X,Y] >: F[X,Y], A0 >: A] = | |
this.asInstanceOf[Machine[F0,A0]] |
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
data Machine k a where | |
Emit :: a -> Machine k a -> Machine k a | |
Await :: k r -> (r -> Machine k a) -> Machine k a -- ignoring fallback for now, not relevant | |
Halt :: Machine k a | |
(++) :: Machine k a -> Machine k a -> Machine k a | |
Halt ++ m2 = m2 | |
(Emit h t) ++ t = Emit h (t ++ m2) | |
(Await req recv) ++ t = Await req (\res -> recv res ++ t) |
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.concurrent | |
import Future._ | |
trait Future[+A] { | |
def flatMap[B](f: A => Future[B]): Future[B] = this match { | |
case Now(a) => More(() => f(a)) | |
case Later(listen) => BindLater(listen, f) | |
case More(force) => BindMore(force, f) | |
case BindLater(listen,g) => More(() => |
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 ExistentialQuantification, GADTs #-} | |
module Control.Process where | |
import Data.Monoid | |
import Prelude hiding (zip, zipWith) | |
import Control.Applicative | |
import System.IO | |
data Process f a = Halt |
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 fpinscala.iomonad | |
trait Throw[+A] { | |
import Throw._ | |
@annotation.tailrec | |
final def run: A = this match { | |
case Done(a) => a | |
case More(thunk) => force(thunk).run | |
} |
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
-- Some edits to the F type | |
data F :: Timing -> * -> * where | |
... | |
{- For each unique `a` value taken on by the first series, call the | |
given function, passing it the `a` wrapped in an `F`, and the | |
subset of issues for each date that have that `a`. | |
sector :: F (P Day) String | |
-- could very well do something using the k |
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
def chooseAny[A](h: Future[A], t: Seq[Future[A]]): Future[(A, Seq[Future[A]])] = { | |
Async { cb => | |
// The details of this implementation are a bit tricky, but the general | |
// idea is to run all `fs` in parallel, returning whichever result | |
// becomes available first. | |
// To account for the fact that the losing computations are still | |
// running, we construct special 'residual' Futures for the losers | |
// that will first return from the already running computation, | |
// then revert back to running the original Future. |
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.stream | |
import scalaz.concurrent.Task | |
import scalaz.syntax.traverse._ | |
import scalaz.std.list._ | |
import Process.Process1 | |
import collection.immutable.{IndexedSeq, Vector} | |
object profile extends App { |
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 woot | |
import scalaz.concurrent._ | |
/* | |
Test to see if `@volatile` is required for mutable fields closed over by an `Actor` | |
using `Strategy.Sequential`. As a test, we have an actor that closes over a integer | |
counter, which it increments for each message it receives. If memory effects are | |
visible to subsequent messages, the count will be equal to the number of messages | |
sent to the actor. |
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
module Window where | |
import Data.Monoid | |
data Window a = Window [a] a [a] deriving (Show,Read) | |
null :: Window a -> Bool | |
null (Window [] _ []) = True | |
null _ = False |