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 scalaz.std.string._ | |
import scalaz.MonadWriter | |
import scalaz.ValidationT | |
import scalaz.WriterT._ | |
object MonadWriterExample extends App { | |
val MW = ValidationT.validationTMonadWriter[Writer, String, String] | |
case class Person(firstName: String, age: Int) |
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 Alacarte { | |
trait Functor[F[_]]{ | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Eval[F[_]] { | |
def F: Functor[F] | |
def evalAlgebra(fa: F[Int]): Int | |
} |
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 Dataflow where | |
import Data.List | |
newtype Id a = Id { unId :: a } | |
class Comonad f where | |
counit :: f a -> a | |
cobind :: (f a -> b) -> f a -> f 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 MultiParamTypeClasses, FunctionalDependencies, RankNTypes, FlexibleInstances, DeriveFunctor, DeriveFoldable, DeriveTraversable, UndecidableInstances #-} | |
module Free where | |
import Control.Monad.Trans | |
import Control.Monad | |
import Data.Traversable | |
import Data.Foldable | |
data Free f a = Pure a | Free (f (Free f a)) |
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
//assuming all akka imports | |
object FutureTest { | |
private case class FutureW[A](proc: ExecutionContext => Future[A]) { // note the similarity with Kleisli[Future, ExecutionContext, A] | |
implicit val defaultDuration = Duration("3s") | |
def map[B](f: A => B) = FutureW(c => proc(c).map(f)) | |
def flatMap[B](f: A => FutureW[B]) = FutureW(c => proc(c).flatMap(a => f(a).apply(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 maybeExample { | |
sealed trait Maybe[A]{ self => | |
def fold[Z](just: A => Z, nothing: => Z): Z | |
def map[B](f: A => B) = fold(a => Just(f(a)), Nothing[B]) | |
def flatMap[B](f: A => Maybe[B]) = new Maybe[B]{ | |
def fold[Z](just: B => Z, nothing: => Z) = | |
self.fold(a => f(a).fold(just, nothing), nothing) | |
} |
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 coprod { | |
trait Functor[F[_]]{ | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
implicit val optionFunctor = new Functor[Option]{ | |
def map[A, B](fa: Option[A])(f: A => B) = fa map f | |
} | |
implicit val listFunctor = new Functor[List]{ |
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.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 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 Binary where | |
import Prelude hiding (head) | |
import Control.Applicative | |
import Control.Monad | |
import qualified Data.ByteString as 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
module Examples where | |
import Control.Applicative | |
import Control.Monad.Trans | |
import Data.Machine | |
data Bit = EMPTY | One | Zero | |
instance Show Bit where |
OlderNewer