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
| 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
| 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 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
| 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
| {-# 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
| module Examples where | |
| import Control.Applicative | |
| import Control.Monad.Trans | |
| import Data.Machine | |
| data Bit = EMPTY | One | Zero | |
| instance Show Bit 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
| {-# LANGUAGE RankNTypes #-} | |
| module Binary where | |
| import Prelude hiding (head) | |
| import Control.Applicative | |
| import Control.Monad | |
| import qualified Data.ByteString as B |
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 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
| 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]{ |