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 vanilla | |
sealed trait Optic[G[_,_] <: Optic[G, _, _], S, A] { | |
def compose[F[_, _] <: Optic[F, _, _], B](o: F[A, B])(implicit lub : Lub[G,F]) : lub.T[S, B] = | |
lub.compose(self, o) | |
def self: G[S,A] | |
def desc: List[String] | |
} | |
case class Traversal[A,B](desc : List[String]) extends Optic[Traversal,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
{-# LANGUAGE ExistentialQuantification #-} | |
module Entities where | |
data Point = TwoD Int Int | ThreeD Int Int Int | |
class Entity a where | |
pos :: a -> Point | |
speed :: a -> Int | |
id :: a -> String |
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
// ------------------------------------------------------ | |
// Combined List/Option/Either | |
// ------------------------------------------------------ | |
object MonadTransformers extends App { | |
import scalaz._ | |
import scalaz.std.option._ | |
import scalaz.std.list._ | |
type OptionTList[α] = OptionT[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
The Union Type Quiz | |
=================== | |
1. Please describe the guiding principle of your typing approach in one sentence: | |
For ADTs, do not (in general) expose the cases as types. | |
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.std.anyVal._ | |
import scalaz.std.tuple._ | |
import scalaz.std.option._ | |
import scalaz.StateT | |
import scalaz.State | |
import scalaz.Trampoline | |
import scalaz.syntax.traverse._ | |
import scalaz.std.list._ | |
import scalaz.Free |
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 java.net.URI | |
import scalaz.concurrent.Promise | |
import scalaz._ | |
import Scalaz._ | |
import language.implicitConversions | |
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] ) | |
trait RequestHeader { |
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 KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
type EEither[+T] = Either[String, T] | |
def toDouble(s: String): EEither[Double] = allCatch.either(s.toDouble).fold(_.toString.left, _.right) | |
def sqrt(d: Double): EEither[Double] = if (d >= 0) math.sqrt(d).right else "sqrt(%s) is too complex for me".format(d).left | |