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 Auths[F[_]](implicit I: Inject[Auth,F]) { | |
def login(id: UserId, pwd: Password): FreeC[F,Option[User]] = | |
lift(Login(id, pwd)) | |
def hasPermission(u: User, p: Permission): FreeC[F,Boolean] = | |
lift(HasPermission(u, p)) | |
type AuthCoyo[A] = Coyoneda[F, A] | |
type AuthFree[A] = Free[AuthCoyo, A] | |
def point[A](a: ⇒ A): Free.FreeC[F, A] = Monad[AuthFree].point(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
import scalaz._, Scalaz._ | |
object Main { | |
trait A | |
trait B | |
trait AB extends A with B | |
type ReadA[T] = Reader[A, T] | |
type ReadB[T] = Reader[B, T] | |
type ReadAB[T] = Reader[AB, 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
module monoidy | |
%default total | |
class Monoidy a where | |
mempty : a | |
mappend : a -> a -> a | |
left_neutrality : (x : a) -> (mappend mempty x = x) | |
right_neutrality : (x : a) -> (mappend x mempty = x) | |
associativity : (x, y, z : a) -> (mappend x (mappend y z) = mappend (mappend x y) z) |
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._ | |
object Main extends App { | |
// two lists we'll be traversing | |
val nonRepeating = List(1,2,3,4) | |
val repeating = List(1,2,3,3,4) | |
// so we can use state to traverse a 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
import scalaz._ | |
import Scalaz._ | |
object Main extends App { | |
def foo[A](list: List[Option[Int]]): Int = { | |
implicit def plus[A] = new ApplicativePlus[({type λ[A]=Int})#λ] { | |
def empty[A] = 0 | |
def plus[A](a: Int, b: ⇒ Int) = a + b | |
def point[A](a: ⇒ A) = a.asInstanceOf[Int] | |
def ap[A, B](fa: => Int)(f: => Int): Int = 0 |
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
java.lang.StackOverflowError | |
at scalaz.syntax.ShowOps.<init>(ShowSyntax.scala:5) | |
at scalaz.syntax.ToShowOps$class.ToShowOps(ShowSyntax.scala:16) | |
at scalaz.Scalaz$.ToShowOps(Scalaz.scala:3) | |
at scalaz.example.CABRunLengthEncoder$.writeOutput(ReaderWriterStateTUsage.scala:143) | |
at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
at scalaz.example.CABRunLengthEncoder$$anonfun$emit$1$$anonfun$apply$7$$anonfun$4.apply(ReaderWriterStateTUsage.scala:154) | |
at scalaz.std.OptionFunctions$class.cata(Option.scala:179) | |
at scalaz.std.option$.cata(Option.scala:231) | |
at scalaz.syntax.std.OptionOps.cata(OptionOps.scala:9) |
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.list._ | |
import scalaz.syntax.traverse._ | |
import scalaz.State._ | |
trait Main { | |
type TypeEnvironment | |
case class GetTypeEnvironment(get: TypeEnvironment) | |
case class Processor(after: GetTypeEnvironment) | |
def performTypeInference(typeEnv: TypeEnvironment, next: Processor): Processor |
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 partition | |
%default total | |
even : Nat -> Bool | |
even x = (mod x 2) == 0 | |
partition' : (a -> Bool) -> List a -> List a | |
partition' f [] = [] | |
partition' f (x :: xs) with (partition' f xs) |
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 natToBin | |
data Parity : Nat -> Type where | |
even : Parity (n + n) | |
odd : Parity (S (n + n)) | |
parity : (n:Nat) -> Parity n | |
natToBin : Nat -> List Bool | |
natToBin Z = Nil |
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.example | |
object RunLengthEncoder extends App { | |
import scalaz._ | |
import scalaz.std.option._ | |
import scalaz.std.anyVal._ | |
import scalaz.syntax.show._ | |
import scalaz.syntax.apply._ | |
/* |