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
// see https://github.com/gseitz/Lensed | |
case class CoState[A, B](put: A => B, pos: A) | |
object CoState { | |
type Store[A, B] = CoState[A, B] | |
} | |
// fused get/set | |
case class Lens[A, B](lens: A => CoState[B, 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
case class ReaderWriterStateT[R, W, S, F[_], A]( | |
run: (R, S) => F[(W, A, S)] | |
) { | |
def map[B](f: A => B)(implicit F: Functor[F]) | |
: ReaderWriterStateT[R, W, S, F, B] = | |
ReaderWriterStateT { | |
case (r, s) => F.map(run(r, s)) { | |
case (w, a, s) => (w, f(a), s) | |
} | |
} |
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
class Functor f => Unzip f where | |
unfzip :: | |
f (a, b) | |
-> (f a, f b) | |
unfzip3 :: | |
f (a, b, c) | |
-> (f a, f b, f c) | |
unfzip3 x = | |
let (a, bc) = unfzip (fmap (\(a', b', c') -> (a', (b', c'))) x) |
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
trait Semigroup[A] { | |
def op(a1: A, a2: A): A | |
} | |
trait Monoid[A] extends Semigroup[A] { | |
def id: A | |
} | |
object EitherFilter { | |
def filterR[A, B](e: Either[A, B])(p: B => Boolean)(implicit M: Monoid[B]): Either[A, 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
case class Swizzler[A](swizzle: String => A) { | |
def map[B](f: A => B): Swizzler[B] = | |
Swizzler(f compose swizzle) | |
def flatMap[B](f: A => Swizzler[B]): Swizzler[B] = | |
Swizzler(s => f(swizzle(s)).swizzle(s)) | |
} | |
object Swizzler { |
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
trait Functor[F[_]] { | |
def fmap[A, B](f: A => B): F[A] => F[B] | |
} | |
trait Extend[F[_]] extends Functor[F] { | |
// coflatmap | |
def extend[A, B](f: F[A] => B): F[A] => F[B] | |
} | |
trait Comonad[F[_]] extends Extend[F] { |
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
trait Functor[F[_]] { | |
def fmap[A, B](f: A => B): F[A] => F[B] | |
} | |
trait Extend[F[_]] extends Functor[F] { | |
// coflatmap | |
def extend[A, B](f: F[A] => B): F[A] => F[B] | |
} | |
trait Comonad[F[_]] extends Extend[F] { |
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
class Semigroupoid cat where | |
(<.>) :: | |
cat a b | |
-> cat b c | |
-> cat a c | |
class Semigroupoid cat => Category cat where | |
identity :: | |
cat a 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
case class Person(name: String, age: Int) | |
object Person | |
case class OtherPerson(name: String, age: Int) | |
object T { | |
def ap[A, B, C](f: (A, B) => C)(a: A, b: B): C = | |
f(a, 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
#!/bin/sh | |
set -e | |
# Base temporary work directory | |
TMP="/tmp" | |
# Glasgow Haskell Compiler version | |
GHCVERSION=7.0.4 |
OlderNewer