@@ -60,19 +60,19 @@ trait Traverse[F[_]] extends Functor[F] with Foldable[F] { self =>
traverseS(fa)(f)(s)

/** Traverse `fa` with a `State[S, G[B]]`, internally using a `Trampoline` to avoid stack overflow. */
def traverseSTrampoline[S, G[+_] : Applicative, A, B](fa: F[A])(f: A => State[S, G[B]]): State[S, G[F[B]]] = {
def traverseSTrampoline[S, G[_] : Applicative, A, B](fa: F[A])(f: A => State[S, G[B]]): State[S, G[F[B]]] = {
import Free._
implicit val A = StateT.stateTMonadState[S, Trampoline].compose(Applicative[G])
implicit val A = StateT.stateTMonadState[S, Trampoline].compose[G]
State[S, G[F[B]]](s => {
val st = traverse[({type λ[α]=StateT[Trampoline, S, G[α]]})#λ, A, B](fa)(f(_: A).lift[Trampoline])(A)
st.run(s).run
})
}

/** Traverse `fa` with a `Kleisli[G, S, B]`, internally using a `Trampoline` to avoid stack overflow. */
def traverseKTrampoline[S, G[+_] : Applicative, A, B](fa: F[A])(f: A => Kleisli[G, S, B]): Kleisli[G, S, F[B]] = {
def traverseKTrampoline[S, G[_] : Applicative, A, B](fa: F[A])(f: A => Kleisli[G, S, B]): Kleisli[G, S, F[B]] = {
import Free._
implicit val A = Kleisli.kleisliMonadReader[Trampoline, S].compose(Applicative[G])
implicit val A = Kleisli.kleisliMonadReader[Trampoline, S].compose[G]
Kleisli[G, S, F[B]](s => {
val kl = traverse[({type λ[α]=Kleisli[Trampoline, S, G[α]]})#λ, A, B](fa)(z => Kleisli[Id, S, G[B]](i => f(z)(i)).lift[Trampoline])(A).run(s)
kl.run
@@ -8,7 +8,7 @@ import Id._
* It implements flatMap+map and drops the write value. There is no `Monoid` or `Semigroup` required. There is no `point` operation.
* You can switch between `WriterT` and `UnwriterT` with `unary_+` and `unary_-`.
*/
sealed trait UnwriterT[F[+_], +U, +A] { self =>
sealed trait UnwriterT[F[_], U, A] { self =>
val run: F[(U, A)]

import UnwriterT._
@@ -41,20 +41,20 @@ sealed trait UnwriterT[F[+_], +U, +A] { self =>
def foreach[B](f: A => Unit)(implicit E: Each[F]): Unit =
E.each(run)(wa => f(wa._2))

def ap[B, UU >: U](f: => UnwriterT[F, UU, A => B])(implicit F: Apply[F]): UnwriterT[F, UU, B] =
def ap[B](f: => UnwriterT[F, U, A => B])(implicit F: Apply[F]): UnwriterT[F, U, B] =
unwriterT {
F.apply2(f.run, run) {
case ((w1, fab), (_, a)) => (w1, fab(a))
}
}

def flatMap[B, UU >: U](f: A => UnwriterT[F, UU, B])(implicit F: Bind[F]): UnwriterT[F, UU, B] =
def flatMap[B](f: A => UnwriterT[F, U, B])(implicit F: Bind[F]): UnwriterT[F, U, B] =
unwriterT(F.bind(run){wa =>
val z = f(wa._2).run
F.map(z)(wb => (wa._1, wb._2))
})

def traverse[G[+_] , B](f: A => G[B])(implicit G: Applicative[G], F: Traverse[F]): G[UnwriterT[F, U, B]] = {
def traverse[G[_], B](f: A => G[B])(implicit G: Applicative[G], F: Traverse[F]): G[UnwriterT[F, U, B]] = {
G.map(F.traverse(run){
case (w, a) => G.map(f(a))(b => (w, b))
})(UnwriterT(_))
@@ -78,7 +78,7 @@ sealed trait UnwriterT[F[+_], +U, +A] { self =>
case (a, b) => G.apply2(f(a), g(b))((_, _))
})(unwriterT(_))

def wpoint[G[+_]](implicit F: Functor[F], P: Applicative[G]): UnwriterT[F, G[U], A] =
def wpoint[G[_]](implicit F: Functor[F], P: Applicative[G]): UnwriterT[F, G[U], A] =
unwriterT(F.map(self.run) {
case (u, a) => (P.point(u), a)
})
@@ -87,48 +87,48 @@ sealed trait UnwriterT[F[+_], +U, +A] { self =>
}

object UnwriterT extends UnwriterTFunctions with UnwriterTInstances {
def apply[F[+_], W, A](v: F[(W, A)]): UnwriterT[F, W, A] =
def apply[F[_], W, A](v: F[(W, A)]): UnwriterT[F, W, A] =
unwriterT(v)
}

trait UnwriterTInstances2 {
implicit def unwriterTFunctor[F[+_], W](implicit F0: Functor[F]) = new UnwriterTFunctor[F, W] {
implicit def unwriterTFunctor[F[_], W](implicit F0: Functor[F]) = new UnwriterTFunctor[F, W] {
implicit def F = F0
}
}

trait UnwriterTInstances1 extends UnwriterTInstances2 {
implicit def unwriterTApply[F[+_], W](implicit F0: Apply[F]) = new UnwriterTApply[F, W] {
implicit def unwriterTApply[F[_], W](implicit F0: Apply[F]) = new UnwriterTApply[F, W] {
implicit def F = F0
}
}

trait UnwriterTInstances0 extends UnwriterTInstances1 {
implicit def unwriterTBifunctor[F[+_]](implicit F0: Functor[F]) = new UnwriterTBifunctor[F] {
implicit def unwriterTBifunctor[F[_]](implicit F0: Functor[F]) = new UnwriterTBifunctor[F] {
implicit def F = F0
}
implicit def unwriterTBind[F[+_], W](implicit F0: Bind[F]) = new UnwriterTBind[F, W] {
implicit def unwriterTBind[F[_], W](implicit F0: Bind[F]) = new UnwriterTBind[F, W] {
implicit def F = F0
}
implicit def unwriterTFoldable[F[+_], W](implicit F0: Foldable[F]) = new UnwriterTFoldable[F, W] {
implicit def unwriterTFoldable[F[_], W](implicit F0: Foldable[F]) = new UnwriterTFoldable[F, W] {
implicit def F = F0
}
implicit def unwriterTEqual[F[+_], W, A](implicit E: Equal[F[(W, A)]]) = E.contramap((_: UnwriterT[F, W, A]).run)
implicit def unwriterTEqual[F[_], W, A](implicit E: Equal[F[(W, A)]]) = E.contramap((_: UnwriterT[F, W, A]).run)
}

trait UnwriterTInstances extends UnwriterTInstances0 {
implicit def unwriterTBitraverse[F[+_]](implicit F0: Traverse[F]) = new UnwriterTBitraverse[F] {
implicit def unwriterTBitraverse[F[_]](implicit F0: Traverse[F]) = new UnwriterTBitraverse[F] {
implicit def F = F0
}
implicit def unwriterComonad[W] = new UnwriterComonad[W] {
implicit def F = implicitly
}
implicit def unwriterTTraverse[F[+_], W](implicit F0: Traverse[F]) = new UnwriterTTraverse[F, W] {
implicit def unwriterTTraverse[F[_], W](implicit F0: Traverse[F]) = new UnwriterTTraverse[F, W] {
implicit def F = F0
}
implicit def unwriterTIndex[W] = new UnwriterTIndex[W] {
}
implicit def unwriterTEach[F[+_], W](implicit F0: Each[F]) = new UnwriterTEach[F, W] {
implicit def unwriterTEach[F[_], W](implicit F0: Each[F]) = new UnwriterTEach[F, W] {
implicit def F = F0
}
implicit def unwriterEqual[W, A](implicit W: Equal[W], A: Equal[A]) = {
@@ -138,7 +138,7 @@ trait UnwriterTInstances extends UnwriterTInstances0 {
}

trait UnwriterTFunctions {
def unwriterT[F[+_], W, A](v: F[(W, A)]): UnwriterT[F, W, A] = new UnwriterT[F, W, A] {
def unwriterT[F[_], W, A](v: F[(W, A)]): UnwriterT[F, W, A] = new UnwriterT[F, W, A] {
val run = v
}

@@ -149,11 +149,11 @@ trait UnwriterTFunctions {

def tell[W](w: W): Unwriter[W, Unit] = unwriter(w -> ())

def unput[F[+_], W, A](value: F[A])(w: W)(implicit F: Functor[F]): UnwriterT[F, W, A] =
def unput[F[_], W, A](value: F[A])(w: W)(implicit F: Functor[F]): UnwriterT[F, W, A] =
UnwriterT(F.map(value)(a => (w, a)))

/** Puts the written value that is produced by applying the given function into a unwriter transformer and associates with `value` */
def unputWith[F[+_], W, A](value: F[A])(w: A => W)(implicit F: Functor[F]): UnwriterT[F, W, A] =
def unputWith[F[_], W, A](value: F[A])(w: A => W)(implicit F: Functor[F]): UnwriterT[F, W, A] =
UnwriterT(F.map(value)(a => (w(a), a)))

}
@@ -162,62 +162,62 @@ trait UnwriterTFunctions {
// Type class implementation traits
//

private[scalaz] trait UnwriterTFunctor[F[+_], W] extends Functor[({type λ[+α]=UnwriterT[F, W, α]})#λ] {
private[scalaz] trait UnwriterTFunctor[F[_], W] extends Functor[({type λ[α]=UnwriterT[F, W, α]})#λ] {
implicit def F: Functor[F]

override def map[A, B](fa: UnwriterT[F, W, A])(f: A => B) = fa map f
}

private[scalaz] trait UnwriterTApply[F[+_], W] extends Apply[({type λ[+α]=UnwriterT[F, W, α]})#λ] with UnwriterTFunctor[F, W] {
private[scalaz] trait UnwriterTApply[F[_], W] extends Apply[({type λ[α]=UnwriterT[F, W, α]})#λ] with UnwriterTFunctor[F, W] {
implicit def F: Apply[F]

override def ap[A, B](fa: => UnwriterT[F, W, A])(f: => UnwriterT[F, W, A => B]) = fa ap f
}

private[scalaz] trait UnwriterTEach[F[+_], W] extends Each[({type λ[+α]=UnwriterT[F, W, α]})#λ] {
private[scalaz] trait UnwriterTEach[F[_], W] extends Each[({type λ[α]=UnwriterT[F, W, α]})#λ] {
implicit def F: Each[F]

def each[A](fa: UnwriterT[F, W, A])(f: A => Unit) = fa foreach f
}

// TODO does Index it make sense for F other than Id?
private[scalaz] trait UnwriterTIndex[W] extends Index[({type λ[+α]=UnwriterT[Id, W, α]})#λ] {
private[scalaz] trait UnwriterTIndex[W] extends Index[({type λ[α]=UnwriterT[Id, W, α]})#λ] {
def index[A](fa: UnwriterT[Id, W, A], i: Int) = if(i == 0) Some(fa.value) else None
}

private[scalaz] trait UnwriterTBind[F[+_], W] extends Bind[({type λ[+α]=UnwriterT[F, W, α]})#λ] with UnwriterTApply[F, W] {
private[scalaz] trait UnwriterTBind[F[_], W] extends Bind[({type λ[α]=UnwriterT[F, W, α]})#λ] with UnwriterTApply[F, W] {
implicit def F: Bind[F]

def bind[A, B](fa: UnwriterT[F, W, A])(f: A => UnwriterT[F, W, B]) = fa flatMap f
}

private[scalaz] trait UnwriterTFoldable[F[+_], W] extends Foldable.FromFoldr[({type λ[+α]=UnwriterT[F, W, α]})#λ] {
private[scalaz] trait UnwriterTFoldable[F[_], W] extends Foldable.FromFoldr[({type λ[α]=UnwriterT[F, W, α]})#λ] {
implicit def F: Foldable[F]

override def foldRight[A, B](fa: UnwriterT[F, W, A], z: => B)(f: (A, => B) => B) = fa.foldRight(z)(f)
}

private[scalaz] trait UnwriterTTraverse[F[+_], W] extends Traverse[({type λ[+α]=UnwriterT[F, W, α]})#λ] with UnwriterTFoldable[F, W] {
private[scalaz] trait UnwriterTTraverse[F[_], W] extends Traverse[({type λ[α]=UnwriterT[F, W, α]})#λ] with UnwriterTFoldable[F, W] {
implicit def F: Traverse[F]

def traverseImpl[G[+_]: Applicative, A, B](fa: UnwriterT[F, W, A])(f: A => G[B]) = fa traverse f
def traverseImpl[G[_]: Applicative, A, B](fa: UnwriterT[F, W, A])(f: A => G[B]) = fa traverse f
}

private[scalaz] trait UnwriterTBifunctor[F[+_]] extends Bifunctor[({type λ[+α, +β]=UnwriterT[F, α, β]})#λ] {
private[scalaz] trait UnwriterTBifunctor[F[_]] extends Bifunctor[({type λ[α, β]=UnwriterT[F, α, β]})#λ] {
implicit def F: Functor[F]

override def bimap[A, B, C, D](fab: UnwriterT[F, A, B])(f: A => C, g: B => D) =
fab.bimap(f, g)
}

private[scalaz] trait UnwriterTBitraverse[F[+_]] extends Bitraverse[({type λ[+α, +β]=UnwriterT[F, α, β]})#λ] with UnwriterTBifunctor[F] {
private[scalaz] trait UnwriterTBitraverse[F[_]] extends Bitraverse[({type λ[α, β]=UnwriterT[F, α, β]})#λ] with UnwriterTBifunctor[F] {
implicit def F: Traverse[F]

def bitraverseImpl[G[_]: Applicative, A, B, C, D](fab: UnwriterT[F, A, B])(f: A => G[C], g: B => G[D]) =
fab.bitraverse(f, g)
}

private[scalaz] trait UnwriterComonad[W] extends Comonad[({type λ[+α] = Unwriter[W, α]})#λ] with UnwriterTFunctor[Id, W] {
private[scalaz] trait UnwriterComonad[W] extends Comonad[({type λ[α] = Unwriter[W, α]})#λ] with UnwriterTFunctor[Id, W] {

override def cojoin[A](fa: Unwriter[W, A]): Unwriter[W, Unwriter[W, A]] =
Unwriter(fa.unwritten, fa)
@@ -104,7 +104,7 @@ sealed trait Validation[+E, +A] {
bimap(f, identity)

/** Binary functor traverse on this validation. */
def bitraverse[G[+_] : Functor, C, D](f: E => G[C], g: A => G[D]): G[Validation[C, D]] = this match {
def bitraverse[G[_] : Functor, C, D](f: E => G[C], g: A => G[D]): G[Validation[C, D]] = this match {
case Failure(a) => Functor[G].map(f(a))(Failure(_))
case Success(b) => Functor[G].map(g(b))(Success(_))
}
@@ -116,7 +116,7 @@ sealed trait Validation[+E, +A] {
}

/** Traverse on the success of this validation. */
def traverse[G[+_] : Applicative, B](f: A => G[B]): G[Validation[E, B]] = this match {
def traverse[G[_] : Applicative, EE >: E, B](f: A => G[B]): G[Validation[EE, B]] = this match {
case Success(a) => Applicative[G].map(f(a))(Success(_))
case Failure(e) => Applicative[G].point(Failure(e))
}
@@ -420,7 +420,7 @@ trait ValidationInstances2 extends ValidationInstances3 {
override def map[A, B](fa: Validation[L, A])(f: A => B) =
fa map f

def traverseImpl[G[+_] : Applicative, A, B](fa: Validation[L, A])(f: A => G[B]) =
def traverseImpl[G[_] : Applicative, A, B](fa: Validation[L, A])(f: A => G[B]) =
fa.traverse(f)

override def foldRight[A, B](fa: Validation[L, A], z: => B)(f: (A, => B) => B) =
@@ -445,7 +445,7 @@ trait ValidationInstances3 {
override def bimap[A, B, C, D](fab: Validation[A, B])
(f: A => C, g: B => D) = fab bimap (f, g)

def bitraverseImpl[G[+_] : Applicative, A, B, C, D](fab: Validation[A, B])
def bitraverseImpl[G[_] : Applicative, A, B, C, D](fab: Validation[A, B])
(f: A => G[C], g: B => G[D]) =
fab.bitraverse(f, g)
}
@@ -2,7 +2,7 @@ package scalaz

import Id._

sealed trait WriterT[F[+_], +W, +A] { self =>
sealed trait WriterT[F[_], W, A] { self =>
val run: F[(W, A)]

import WriterT._
@@ -29,19 +29,19 @@ sealed trait WriterT[F[+_], +W, +A] { self =>
def swap(implicit F: Functor[F]): WriterT[F, A, W] =
mapValue(wa => (wa._2, wa._1))

def :++>[WW >: W](w: => WW)(implicit F: Functor[F], W: Semigroup[WW]): WriterT[F, WW, A] =
def :++>(w: => W)(implicit F: Functor[F], W: Semigroup[W]): WriterT[F, W, A] =
mapWritten(W.append(_, w))

def :++>>[WW >: W](f: A => WW)(implicit F: Functor[F], W: Semigroup[WW]): WriterT[F, WW, A] =
def :++>>(f: A => W)(implicit F: Functor[F], W: Semigroup[W]): WriterT[F, W, A] =
mapValue(wa => (W.append(wa._1, f(wa._2)), wa._2))

def <++:[WW >: W](w: => WW)(implicit F: Functor[F], W: Semigroup[WW]): WriterT[F, WW, A] =
def <++:(w: => W)(implicit F: Functor[F], W: Semigroup[W]): WriterT[F, W, A] =
mapWritten(W.append(w, _))

def <<++:[WW >: W](f: A => WW)(implicit F: Functor[F], s: Semigroup[WW]): WriterT[F, WW, A] =
def <<++:(f: A => W)(implicit F: Functor[F], s: Semigroup[W]): WriterT[F, W, A] =
mapValue(wa => (s.append(f(wa._2), wa._1), wa._2))

def reset[WW >: W](implicit Z: Monoid[WW], F: Functor[F]): WriterT[F, WW, A] =
def reset(implicit Z: Monoid[W], F: Functor[F]): WriterT[F, W, A] =
mapWritten(_ => Z.zero)

def map[B](f: A => B)(implicit F: Functor[F]): WriterT[F, W, B] =
@@ -50,19 +50,19 @@ sealed trait WriterT[F[+_], +W, +A] { self =>
def foreach[B](f: A => Unit)(implicit E: Each[F]): Unit =
E.each(run)(wa => f(wa._2))

def ap[B, WW >: W](f: => WriterT[F, WW, A => B])(implicit F: Apply[F], W: Semigroup[WW]): WriterT[F, WW, B] = writerT {
def ap[B](f: => WriterT[F, W, A => B])(implicit F: Apply[F], W: Semigroup[W]): WriterT[F, W, B] = writerT {
F.apply2(f.run, run) {
case ((w1, fab), (w2, a)) => (W.append(w1, w2), fab(a))
}
}

def flatMap[B, WW >: W](f: A => WriterT[F, WW, B])(implicit F: Bind[F], s: Semigroup[WW]): WriterT[F, WW, B] =
def flatMap[B](f: A => WriterT[F, W, B])(implicit F: Bind[F], s: Semigroup[W]): WriterT[F, W, B] =
writerT(F.bind(run){wa =>
val z = f(wa._2).run
F.map(z)(wb => (s.append(wa._1, wb._1), wb._2))
})

def traverse[G[+_] , B](f: A => G[B])(implicit G: Applicative[G], F: Traverse[F]): G[WriterT[F, W, B]] = {
def traverse[G[_], B](f: A => G[B])(implicit G: Applicative[G], F: Traverse[F]): G[WriterT[F, W, B]] = {
G.map(F.traverse(run){
case (w, a) => G.map(f(a))(b => (w, b))
})(WriterT(_))
@@ -92,7 +92,7 @@ sealed trait WriterT[F[+_], +W, +A] { self =>
}
)

def wpoint[G[+_]](implicit F: Functor[F], P: Applicative[G]): WriterT[F, G[W], A] =
def wpoint[G[_]](implicit F: Functor[F], P: Applicative[G]): WriterT[F, G[W], A] =
writerT(F.map(self.run) {
case (w, a) => (P.point(w), a)
})
@@ -101,7 +101,7 @@ sealed trait WriterT[F[+_], +W, +A] { self =>
}

object WriterT extends WriterTFunctions with WriterTInstances {
def apply[F[+_], W, A](v: F[(W, A)]): WriterT[F, W, A] =
def apply[F[_], W, A](v: F[(W, A)]): WriterT[F, W, A] =
writerT(v)
}

@@ -111,7 +111,7 @@ trait WriterTInstances12 {
}
}
trait WriterTInstances11 extends WriterTInstances12 {
implicit def writerTFunctor[F[+_], W](implicit F0: Functor[F]) = new WriterTFunctor[F, W] {
implicit def writerTFunctor[F[_], W](implicit F0: Functor[F]) = new WriterTFunctor[F, W] {
implicit def F = F0
}
}
@@ -124,7 +124,7 @@ trait WriterTInstances10 extends WriterTInstances11 {
}

trait WriterTInstances9 extends WriterTInstances10 {
implicit def writerTApply[F[+_], W](implicit W0: Semigroup[W], F0: Apply[F]) = new WriterTApply[F, W] {
implicit def writerTApply[F[_], W](implicit W0: Semigroup[W], F0: Apply[F]) = new WriterTApply[F, W] {
implicit def F = F0
implicit def W = W0
}
@@ -138,7 +138,7 @@ trait WriterTInstances8 extends WriterTInstances9 {
}

trait WriterTInstances7 extends WriterTInstances8 {
implicit def writerTApplicative[F[+_], W](implicit W0: Monoid[W], F0: Applicative[F]) = new WriterTApplicative[F, W] {
implicit def writerTApplicative[F[_], W](implicit W0: Monoid[W], F0: Applicative[F]) = new WriterTApplicative[F, W] {
implicit def F = F0
implicit def W = W0
}
@@ -152,7 +152,7 @@ trait WriterTInstances6 extends WriterTInstances7 {
}

trait WriterTInstance5 extends WriterTInstances6 {
implicit def writerTMonad[F[+_], W](implicit W0: Monoid[W], F0: Monad[F]) = new WriterTMonad[F, W] {
implicit def writerTMonad[F[_], W](implicit W0: Monoid[W], F0: Monad[F]) = new WriterTMonad[F, W] {
implicit def F = F0
implicit def W = W0
}
@@ -169,13 +169,13 @@ trait WriterTInstances4 extends WriterTInstance5 {
}

trait WriterTInstances3 extends WriterTInstances4 {
implicit def writerTBifunctor[F[+_]](implicit F0: Functor[F]) = new WriterTBifunctor[F] {
implicit def writerTBifunctor[F[_]](implicit F0: Functor[F]) = new WriterTBifunctor[F] {
implicit def F = F0
}
implicit def writerTFoldable[F[+_], W](implicit F0: Foldable[F]) = new WriterTFoldable[F, W] {
implicit def writerTFoldable[F[_], W](implicit F0: Foldable[F]) = new WriterTFoldable[F, W] {
implicit def F = F0
}
implicit def writerTEqual[F[+_], W, A](implicit E: Equal[F[(W, A)]]) = E.contramap((_: WriterT[F, W, A]).run)
implicit def writerTEqual[F[_], W, A](implicit E: Equal[F[(W, A)]]) = E.contramap((_: WriterT[F, W, A]).run)
}

trait WriterTInstances2 extends WriterTInstances3 {
@@ -197,32 +197,32 @@ trait WriterTInstances1 extends WriterTInstances2 {
}

trait WriterTInstances0 extends WriterTInstances1 {
implicit def writerTBitraverse[F[+_]](implicit F0: Traverse[F]) = new WriterTBitraverse[F] {
implicit def writerTBitraverse[F[_]](implicit F0: Traverse[F]) = new WriterTBitraverse[F] {
implicit def F = F0
}
implicit def writerTTraverse[F[+_], W](implicit F0: Traverse[F]) = new WriterTTraverse[F, W] {
implicit def writerTTraverse[F[_], W](implicit F0: Traverse[F]) = new WriterTTraverse[F, W] {
implicit def F = F0
}
implicit def writerTIndex[W] = new WriterTIndex[W] {
}
implicit def writerEach[F[+_], W](implicit F0: Each[F]) = new WriterTEach[F, W] {
implicit def writerEach[F[_], W](implicit F0: Each[F]) = new WriterTEach[F, W] {
implicit def F = F0
}
}

trait WriterTInstances extends WriterTInstances0 {
implicit def writerTMonadListen[F[+_], W](implicit F0: Monad[F], W0: Monoid[W]) = new WriterMonadListen[F, W] {
implicit def writerTMonadListen[F[_], W](implicit F0: Monad[F], W0: Monoid[W]) = new WriterMonadListen[F, W] {
implicit def F = F0
implicit def W = W0
}

implicit def writerTMonadTrans[W](implicit W0: Monoid[W]): MonadTrans[({type λ[α[+_], β] = WriterT[α, W, β]})#λ] = new WriterTMonadTrans[W] {
implicit def writerTMonadTrans[W](implicit W0: Monoid[W]): MonadTrans[({type λ[α[_], β] = WriterT[α, W, β]})#λ] = new WriterTMonadTrans[W] {
implicit def W = W0
}
}

trait WriterTFunctions {
def writerT[F[+_], W, A](v: F[(W, A)]): WriterT[F, W, A] = new WriterT[F, W, A] {
def writerT[F[_], W, A](v: F[(W, A)]): WriterT[F, W, A] = new WriterT[F, W, A] {
val run = v
}

@@ -233,11 +233,11 @@ trait WriterTFunctions {

def tell[W](w: W): Writer[W, Unit] = writer(w -> ())

def put[F[+_], W, A](value: F[A])(w: W)(implicit F: Functor[F]): WriterT[F, W, A] =
def put[F[_], W, A](value: F[A])(w: W)(implicit F: Functor[F]): WriterT[F, W, A] =
WriterT(F.map(value)(a => (w, a)))

/** Puts the written value that is produced by applying the given function into a writer transformer and associates with `value` */
def putWith[F[+_], W, A](value: F[A])(w: A => W)(implicit F: Functor[F]): WriterT[F, W, A] =
def putWith[F[_], W, A](value: F[A])(w: A => W)(implicit F: Functor[F]): WriterT[F, W, A] =
WriterT(F.map(value)(a => (w(a), a)))

}
@@ -247,69 +247,69 @@ trait WriterTFunctions {
//
import WriterT.writerT

private[scalaz] trait WriterTFunctor[F[+_], W] extends Functor[({type λ[+α]=WriterT[F, W, α]})#λ] {
private[scalaz] trait WriterTFunctor[F[_], W] extends Functor[({type λ[α]=WriterT[F, W, α]})#λ] {
implicit def F: Functor[F]

override def map[A, B](fa: WriterT[F, W, A])(f: A => B) = fa map f
}

private[scalaz] trait WriterTApply[F[+_], W] extends Apply[({type λ[+α]=WriterT[F, W, α]})#λ] with WriterTFunctor[F, W] {
private[scalaz] trait WriterTApply[F[_], W] extends Apply[({type λ[α]=WriterT[F, W, α]})#λ] with WriterTFunctor[F, W] {
implicit def F: Apply[F]
implicit def W: Semigroup[W]

override def ap[A, B](fa: => WriterT[F, W, A])(f: => WriterT[F, W, A => B]) = fa ap f
}

private[scalaz] trait WriterTApplicative[F[+_], W] extends Applicative[({type λ[+α]=WriterT[F, W, α]})#λ] with WriterTApply[F, W] {
private[scalaz] trait WriterTApplicative[F[_], W] extends Applicative[({type λ[α]=WriterT[F, W, α]})#λ] with WriterTApply[F, W] {
implicit def F: Applicative[F]
implicit def W: Monoid[W]
def point[A](a: => A) = writerT(F.point((W.zero, a)))
}

private[scalaz] trait WriterTEach[F[+_], W] extends Each[({type λ[+α]=WriterT[F, W, α]})#λ] {
private[scalaz] trait WriterTEach[F[_], W] extends Each[({type λ[α]=WriterT[F, W, α]})#λ] {
implicit def F: Each[F]

def each[A](fa: WriterT[F, W, A])(f: A => Unit) = fa foreach f
}

// TODO does Index it make sense for F other than Id?
private[scalaz] trait WriterTIndex[W] extends Index[({type λ[+α]=WriterT[Id, W, α]})#λ] {
private[scalaz] trait WriterTIndex[W] extends Index[({type λ[α]=WriterT[Id, W, α]})#λ] {
def index[A](fa: WriterT[Id, W, A], i: Int) = if(i == 0) Some(fa.value) else None
}

private[scalaz] trait WriterTMonad[F[+_], W] extends Monad[({type λ[+α]=WriterT[F, W, α]})#λ] with WriterTApplicative[F, W] {
private[scalaz] trait WriterTMonad[F[_], W] extends Monad[({type λ[α]=WriterT[F, W, α]})#λ] with WriterTApplicative[F, W] {
implicit def F: Monad[F]

def bind[A, B](fa: WriterT[F, W, A])(f: A => WriterT[F, W, B]) = fa flatMap f
}

private[scalaz] trait WriterTFoldable[F[+_], W] extends Foldable.FromFoldr[({type λ[+α]=WriterT[F, W, α]})#λ] {
private[scalaz] trait WriterTFoldable[F[_], W] extends Foldable.FromFoldr[({type λ[α]=WriterT[F, W, α]})#λ] {
implicit def F: Foldable[F]

override def foldRight[A, B](fa: WriterT[F, W, A], z: => B)(f: (A, => B) => B) = fa.foldRight(z)(f)
}

private[scalaz] trait WriterTTraverse[F[+_], W] extends Traverse[({type λ[+α]=WriterT[F, W, α]})#λ] with WriterTFoldable[F, W] {
private[scalaz] trait WriterTTraverse[F[_], W] extends Traverse[({type λ[α]=WriterT[F, W, α]})#λ] with WriterTFoldable[F, W] {
implicit def F: Traverse[F]

def traverseImpl[G[+_]: Applicative, A, B](fa: WriterT[F, W, A])(f: A => G[B]) = fa traverse f
def traverseImpl[G[_]: Applicative, A, B](fa: WriterT[F, W, A])(f: A => G[B]) = fa traverse f
}

private[scalaz] trait WriterTBifunctor[F[+_]] extends Bifunctor[({type λ[+α, +β]=WriterT[F, α, β]})#λ] {
private[scalaz] trait WriterTBifunctor[F[_]] extends Bifunctor[({type λ[α, β]=WriterT[F, α, β]})#λ] {
implicit def F: Functor[F]

override def bimap[A, B, C, D](fab: WriterT[F, A, B])(f: A => C, g: B => D) =
fab.bimap(f, g)
}

private[scalaz] trait WriterTBitraverse[F[+_]] extends Bitraverse[({type λ[+α, +β]=WriterT[F, α, β]})#λ] with WriterTBifunctor[F] {
private[scalaz] trait WriterTBitraverse[F[_]] extends Bitraverse[({type λ[α, β]=WriterT[F, α, β]})#λ] with WriterTBifunctor[F] {
implicit def F: Traverse[F]

def bitraverseImpl[G[_]: Applicative, A, B, C, D](fab: WriterT[F, A, B])(f: A => G[C], g: B => G[D]) =
fab.bitraverse(f, g)
}

private[scalaz] trait WriterComonad[W] extends Comonad[({type λ[+α] = Writer[W, α]})#λ] with WriterTFunctor[Id, W] {
private[scalaz] trait WriterComonad[W] extends Comonad[({type λ[α] = Writer[W, α]})#λ] with WriterTFunctor[Id, W] {
def copoint[A](p: Writer[W, A]): A = p.value

override def cojoin[A](fa: Writer[W, A]): Writer[W, Writer[W, A]] =
@@ -319,16 +319,16 @@ private[scalaz] trait WriterComonad[W] extends Comonad[({type λ[+α] = Writer[W
Writer(fa.written, f(fa))
}

private[scalaz] trait WriterTMonadTrans[W] extends MonadTrans[({type λ[α[+_], β] = WriterT[α, W, β]})#λ] {
def liftM[M[+_], B](mb: M[B])(implicit M: Monad[M]): WriterT[M, W, B] =
private[scalaz] trait WriterTMonadTrans[W] extends MonadTrans[({type λ[α[_], β] = WriterT[α, W, β]})#λ] {
def liftM[M[_], B](mb: M[B])(implicit M: Monad[M]): WriterT[M, W, B] =
WriterT(M.map(mb)((W.zero, _)))

implicit def W: Monoid[W]

implicit def apply[M[+_]: Monad]: Monad[({type λ[α]=WriterT[M, W, α]})#λ] = WriterT.writerTMonad
implicit def apply[M[_]: Monad]: Monad[({type λ[α]=WriterT[M, W, α]})#λ] = WriterT.writerTMonad
}

private[scalaz] trait WriterMonadListen[F[+_], W] extends MonadListen[({type λ[+α, +β] = WriterT[F, α, β]})#λ, W] with WriterTMonad[F, W] {
private[scalaz] trait WriterMonadListen[F[_], W] extends MonadListen[({type λ[α, β] = WriterT[F, α, β]})#λ, W] with WriterTMonad[F, W] {
implicit def F: Monad[F]
implicit def W: Monoid[W]

@@ -105,12 +105,12 @@ package object scalaz {

type |>=|[G[_], F[_]] = MonadPartialOrder[G, F]

type ReaderT[F[+_], -E, +A] = Kleisli[F, E, A]
type =?>[-E, +A] = Kleisli[Option, E, A]
type Reader[-E, +A] = ReaderT[Id, E, A]
type ReaderT[F[_], E, A] = Kleisli[F, E, A]
type =?>[E, A] = Kleisli[Option, E, A]
type Reader[E, A] = ReaderT[Id, E, A]

type Writer[+W, +A] = WriterT[Id, W, A]
type Unwriter[+W, +A] = UnwriterT[Id, W, A]
type Writer[W, A] = WriterT[Id, W, A]
type Unwriter[W, A] = UnwriterT[Id, W, A]

object Reader {
def apply[E, A](f: E => A): Reader[E, A] = Kleisli[Id, E, A](f)
@@ -129,14 +129,14 @@ package object scalaz {
*
* [[http://www.youtube.com/watch?feature=player_detailpage&v=XVmhK8WbRLY#t=585s An introduction to the State Monad]]
*/
type StateT[F[+_], S, +A] = IndexedStateT[F, S, S, A]
type IndexedState[-S1, +S2, +A] = IndexedStateT[Id, S1, S2, A]
type StateT[F[_], S, A] = IndexedStateT[F, S, S, A]
type IndexedState[-S1, S2, A] = IndexedStateT[Id, S1, S2, A]
/** A state transition, representing a function `S => (A, S)`. */
type State[S, +A] = StateT[Id, S, A]
type State[S, A] = StateT[Id, S, A]

// important to define here, rather than at the top-level, to avoid Scala 2.9.2 bug
object StateT extends StateTFunctions with StateTInstances {
def apply[F[+_], S, A](f: S => F[(S, A)]): StateT[F, S, A] = new StateT[F, S, A] {
def apply[F[_], S, A](f: S => F[(S, A)]): StateT[F, S, A] = new StateT[F, S, A] {
def apply(s: S) = f(s)
}
}
@@ -151,13 +151,13 @@ package object scalaz {
}
}

type StoreT[F[+_], A, +B] = IndexedStoreT[F, A, A, B]
type IndexedStore[+I, -A, +B] = IndexedStoreT[Id, I, A, B]
type Store[A, +B] = StoreT[Id, A, B]
type StoreT[F[_], A, B] = IndexedStoreT[F, A, A, B]
type IndexedStore[I, A, B] = IndexedStoreT[Id, I, A, B]
type Store[A, B] = StoreT[Id, A, B]
// flipped
type |-->[+A, B] = Store[B, A]
type |-->[A, B] = Store[B, A]
object StoreT extends StoreTFunctions with StoreTInstances {
def apply[F[+_], A, B](r: (F[A => B], A)): StoreT[F, A, B] =
def apply[F[_], A, B](r: (F[A => B], A)): StoreT[F, A, B] =
storeT(r)
}
object IndexedStore {
@@ -168,25 +168,25 @@ package object scalaz {
}


type ReaderWriterStateT[F[+_], -R, +W, S, +A] = IndexedReaderWriterStateT[F, R, W, S, S, A]
type ReaderWriterStateT[F[_], -R, W, S, A] = IndexedReaderWriterStateT[F, R, W, S, S, A]
object ReaderWriterStateT extends ReaderWriterStateTFunctions with ReaderWriterStateTInstances {
def apply[F[+_], R, W, S, A](f: (R, S) => F[(W, A, S)]): ReaderWriterStateT[F, R, W, S, A] = IndexedReaderWriterStateT[F, R, W, S, S, A] { (r: R, s: S) => f(r, s) }
def apply[F[_], R, W, S, A](f: (R, S) => F[(W, A, S)]): ReaderWriterStateT[F, R, W, S, A] = IndexedReaderWriterStateT[F, R, W, S, S, A] { (r: R, s: S) => f(r, s) }
}
type IndexedReaderWriterState[-R, +W, -S1, +S2, +A] = IndexedReaderWriterStateT[Id, R, W, S1, S2, A]
type IndexedReaderWriterState[-R, W, -S1, S2, A] = IndexedReaderWriterStateT[Id, R, W, S1, S2, A]
object IndexedReaderWriterState extends ReaderWriterStateTFunctions with ReaderWriterStateTInstances {
def apply[R, W, S1, S2, A](f: (R, S1) => (W, A, S2)): IndexedReaderWriterState[R, W, S1, S2, A] = IndexedReaderWriterStateT[Id, R, W, S1, S2, A] { (r: R, s: S1) => f(r, s) }
}
type ReaderWriterState[-R, +W, S, +A] = ReaderWriterStateT[Id, R, W, S, A]
type ReaderWriterState[-R, W, S, A] = ReaderWriterStateT[Id, R, W, S, A]
object ReaderWriterState extends ReaderWriterStateTFunctions with ReaderWriterStateTInstances {
def apply[R, W, S, A](f: (R, S) => (W, A, S)): ReaderWriterState[R, W, S, A] = IndexedReaderWriterStateT[Id, R, W, S, S, A] { (r: R, s: S) => f(r, s) }
}
type IRWST[F[+_], -R, +W, -S1, +S2, +A] = IndexedReaderWriterStateT[F, R, W, S1, S2, A]
type IRWST[F[_], -R, W, -S1, S2, A] = IndexedReaderWriterStateT[F, R, W, S1, S2, A]
val IRWST: IndexedReaderWriterStateT.type = IndexedReaderWriterStateT
type IRWS[-R, +W, -S1, +S2, +A] = IndexedReaderWriterState[R, W, S1, S2, A]
type IRWS[-R, W, -S1, S2, A] = IndexedReaderWriterState[R, W, S1, S2, A]
val IRWS: IndexedReaderWriterState.type = IndexedReaderWriterState
type RWST[F[+_], -R, +W, S, +A] = ReaderWriterStateT[F, R, W, S, A]
type RWST[F[_], -R, W, S, A] = ReaderWriterStateT[F, R, W, S, A]
val RWST: ReaderWriterStateT.type = ReaderWriterStateT
type RWS[-R, +W, S, +A] = ReaderWriterState[R, W, S, A]
type RWS[-R, W, S, A] = ReaderWriterState[R, W, S, A]
val RWS: ReaderWriterState.type = ReaderWriterState

type Alternative[F[_]] = ApplicativePlus[F]
@@ -236,37 +236,37 @@ package object scalaz {

type @?>[A, B] = PLens[A, B]

type PIndexedStateT[F[+_], -S1, +S2, +A] = IndexedStateT[F, S1, S2, Option[A]]
type PStateT[F[+_], S, +A] = PIndexedStateT[F, S, S, A]
type PIndexedStateT[F[_], -S1, S2, A] = IndexedStateT[F, S1, S2, Option[A]]
type PStateT[F[_], S, A] = PIndexedStateT[F, S, S, A]

type PIndexedState[-S1, +S2, +A] = PIndexedStateT[Id, S1, S2, A]
type PState[S, +A] = PStateT[Id, S, A]
type PIndexedState[-S1, S2, A] = PIndexedStateT[Id, S1, S2, A]
type PState[S, A] = PStateT[Id, S, A]

type IndexedConts[W[+_], +R, -O, +A] = IndexedContsT[W, Id, R, O, A]
type IndexedConts[W[_], R, O, A] = IndexedContsT[W, Id, R, O, A]
object IndexedConts extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[W[+_], R, O, A](f: W[A => O] => R): IndexedConts[W, R, O, A] = IndexedContsT[W, Id, R, O, A](f)
def apply[W[_], R, O, A](f: W[A => O] => R): IndexedConts[W, R, O, A] = IndexedContsT[W, Id, R, O, A](f)
}
type IndexedContT[M[+_], +R, -O, +A] = IndexedContsT[Id, M, R, O, A]
type IndexedContT[M[_], R, O, A] = IndexedContsT[Id, M, R, O, A]
object IndexedContT extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[M[+_], R, O, A](f: (A => M[O]) => M[R]): IndexedContT[M, R, O, A] = IndexedContsT[Id, M, R, O, A](f)
def apply[M[_], R, O, A](f: (A => M[O]) => M[R]): IndexedContT[M, R, O, A] = IndexedContsT[Id, M, R, O, A](f)
}
type IndexedCont[+R, -O, +A] = IndexedContT[Id, R, O, A]
type IndexedCont[R, O, A] = IndexedContT[Id, R, O, A]
object IndexedCont extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[W[+_], R, O, A](f: (A => O) => R): IndexedCont[R, O, A] = IndexedContsT[Id, Id, R, O, A](f)
def apply[W[_], R, O, A](f: (A => O) => R): IndexedCont[R, O, A] = IndexedContsT[Id, Id, R, O, A](f)
}
type ContsT[W[+_], M[+_], R, +A] = IndexedContsT[W, M, R, R, A]
type ContsT[W[_], M[_], R, A] = IndexedContsT[W, M, R, R, A]
object ContsT extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[W[+_], M[+_], R, A](f: W[A => M[R]] => M[R]): ContsT[W, M, R, A] = IndexedContsT[W, M, R, R, A](f)
def apply[W[_], M[_], R, A](f: W[A => M[R]] => M[R]): ContsT[W, M, R, A] = IndexedContsT[W, M, R, R, A](f)
}
type Conts[W[+_], R, +A] = ContsT[W, Id, R, A]
type Conts[W[_], R, A] = ContsT[W, Id, R, A]
object Conts extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[W[+_], R, A](f: W[A => R] => R): Conts[W, R, A] = IndexedContsT[W, Id, R, R, A](f)
def apply[W[_], R, A](f: W[A => R] => R): Conts[W, R, A] = IndexedContsT[W, Id, R, R, A](f)
}
type ContT[M[+_], R, +A] = ContsT[Id, M, R, A]
type ContT[M[_], R, A] = ContsT[Id, M, R, A]
object ContT extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[M[+_], R, A](f: (A => M[R]) => M[R]): ContT[M, R, A] = IndexedContsT[Id, M, R, R, A](f)
def apply[M[_], R, A](f: (A => M[R]) => M[R]): ContT[M, R, A] = IndexedContsT[Id, M, R, R, A](f)
}
type Cont[R, +A] = ContT[Id, R, A]
type Cont[R, A] = ContT[Id, R, A]
object Cont extends IndexedContsTFunctions with IndexedContsTInstances {
def apply[R, A](f: (A => R) => R): Cont[R, A] = IndexedContsT[Id, Id, R, R, A](f)
}
@@ -38,7 +38,7 @@ trait TraverseOps[F[_],A] extends Ops[F[A]] {
* A version of `traverse` specialized for `State[S, G[B]]` that internally uses a `Trampoline`
* to avoid stack-overflow.
*/
final def traverseSTrampoline[G[+_]: Applicative, S, B](f: A => State[S, G[B]]): State[S, G[F[B]]] =
final def traverseSTrampoline[G[_]: Applicative, S, B](f: A => State[S, G[B]]): State[S, G[F[B]]] =
F.traverseSTrampoline[S, G, A, B](self)(f)

/**
@@ -3,9 +3,9 @@ package effect

/**Duplicate a handle in the parent region. */
trait Dup[H[_[_]]] {
def dup[PP[+_] : MonadIO, CS, PS]:
H[({type λ[+α] = RegionT[CS, ({type λ[+β] = RegionT[PS, PP, β]})#λ, α]})#λ] =>
RegionT[CS, ({type λ[+α] = RegionT[PS, PP, α]})#λ, H[({type λ[+β] = RegionT[PS, PP, β]})#λ]]
def dup[PP[_] : MonadIO, CS, PS]:
H[({type λ[α] = RegionT[CS, ({type λ[β] = RegionT[PS, PP, β]})#λ, α]})#λ] =>
RegionT[CS, ({type λ[α] = RegionT[PS, PP, α]})#λ, H[({type λ[β] = RegionT[PS, PP, β]})#λ]]
}

object Dup extends DupFunctions with DupInstances
@@ -14,28 +14,28 @@ trait DupInstances {
import Dup._

implicit val FinalizerHandleDup: Dup[FinalizerHandle] = new Dup[FinalizerHandle] {
def dup[PP[+_] : MonadIO, CS, PS]:
FinalizerHandle[({type λ[+α] = RegionT[CS, ({type λ[+β] = RegionT[PS, PP, β]})#λ, α]})#λ] =>
RegionT[CS, ({type λ[+α] = RegionT[PS, PP, α]})#λ, FinalizerHandle[({type λ[+β] = RegionT[PS, PP, β]})#λ]] = h =>
RegionT[CS, ({type λ[+α] = RegionT[PS, PP, α]})#λ, FinalizerHandle[({type λ[+β] = RegionT[PS, PP, β]})#λ]](
Kleisli[({type λ[+α] = RegionT[PS, PP, α]})#λ, IORef[List[RefCountedFinalizer]],
FinalizerHandle[({type λ[+β] = RegionT[PS, PP, β]})#λ]](hsIORef =>
copy[PS, PP, ({type λ[+α] = RegionT[CS, ({type λ[+β] = RegionT[PS, PP, β]})#λ, α]})#λ](h)))
def dup[PP[_] : MonadIO, CS, PS]:
FinalizerHandle[({type λ[α] = RegionT[CS, ({type λ[β] = RegionT[PS, PP, β]})#λ, α]})#λ] =>
RegionT[CS, ({type λ[α] = RegionT[PS, PP, α]})#λ, FinalizerHandle[({type λ[β] = RegionT[PS, PP, β]})#λ]] = h =>
RegionT[CS, ({type λ[α] = RegionT[PS, PP, α]})#λ, FinalizerHandle[({type λ[β] = RegionT[PS, PP, β]})#λ]](
Kleisli[({type λ[α] = RegionT[PS, PP, α]})#λ, IORef[List[RefCountedFinalizer]],
FinalizerHandle[({type λ[β] = RegionT[PS, PP, β]})#λ]](hsIORef =>
copy[PS, PP, ({type λ[α] = RegionT[CS, ({type λ[β] = RegionT[PS, PP, β]})#λ, α]})#λ](h)))
}
}

trait DupFunctions {

/**Duplicates a handle to its parent region. */
def dup[H[_[_]] : Dup, PP[+_] : MonadIO, CS, PS](h: H[({type λ[+α] = RegionT[CS, ({type λ[+β] = RegionT[PS, PP, β]})#λ, α]})#λ]):
RegionT[CS, ({type λ[+α] = RegionT[PS, PP, α]})#λ, H[({type λ[+β] = RegionT[PS, PP, β]})#λ]] = implicitly[Dup[H]].dup.apply(h)
def dup[H[_[_]] : Dup, PP[_] : MonadIO, CS, PS](h: H[({type λ[α] = RegionT[CS, ({type λ[β] = RegionT[PS, PP, β]})#λ, α]})#λ]):
RegionT[CS, ({type λ[α] = RegionT[PS, PP, α]})#λ, H[({type λ[β] = RegionT[PS, PP, β]})#λ]] = implicitly[Dup[H]].dup.apply(h)

def copy[S, P[+_] : MonadIO, R[_]](h: FinalizerHandle[R]):
RegionT[S, P, FinalizerHandle[({type λ[+α] = RegionT[S, P, α]})#λ]] = h match {
def copy[S, P[_] : MonadIO, R[_]](h: FinalizerHandle[R]):
RegionT[S, P, FinalizerHandle[({type λ[α] = RegionT[S, P, α]})#λ]] = h match {
case h =>
RegionT(Kleisli(hsIORef => (for {
_ <- h.finalizer.refcount.mod(_ + 1)
_ <- hsIORef.mod(h.finalizer :: _)
} yield FinalizerHandle[({type λ[+α] = RegionT[S, P, α]})#λ](h.finalizer)).liftIO[P]))
} yield FinalizerHandle[({type λ[α] = RegionT[S, P, α]})#λ](h.finalizer)).liftIO[P]))
}
}
@@ -11,7 +11,7 @@ import Free._
import std.function._
import syntax.bifunctor._

sealed trait IO[+A] {
sealed trait IO[A] {
private[effect] def apply(rw: Tower[IvoryTower]): Trampoline[(Tower[IvoryTower], A)]

import IO._
@@ -64,18 +64,18 @@ sealed trait IO[+A] {
})

/** Lift this action to a given IO-like monad. */
def liftIO[M[+_]](implicit m: MonadIO[M]): M[A] =
def liftIO[M[_]](implicit m: MonadIO[M]): M[A] =
m.liftIO(this)

/** Executes the handler if an exception is raised. */
def except[B >: A](handler: Throwable => IO[B]): IO[B] =
def except(handler: Throwable => IO[A]): IO[A] =
io(rw => try { Return(this(rw).run) } catch { case e => handler(e)(rw) })

/**
* Executes the handler for exceptions that are raised and match the given predicate.
* Other exceptions are rethrown.
*/
def catchSome[B,C >: A](p: Throwable => Option[B], handler: B => IO[C]): IO[C] =
def catchSome[B](p: Throwable => Option[B], handler: B => IO[A]): IO[A] =
except(e => p(e) match {
case Some(z) => handler(z)
case None => throw e
@@ -86,7 +86,7 @@ sealed trait IO[+A] {
* exception was raised.
*/
def catchLeft: IO[Throwable \/ A] =
map(\/.right) except (t => IO(\/.left(t)))
map(\/.right[Throwable, A]) except (t => IO(-\/(t)))

/**Like "catchLeft" but takes a predicate to select which exceptions are caught. */
def catchSomeLeft[B](p: Throwable => Option[B]): IO[B \/ A] =
@@ -128,7 +128,7 @@ sealed trait IO[+A] {
controlIO((runInIO: RunInBase[M, IO]) => bracket(after)(runInIO.apply compose during))

/** An automatic resource management. */
def using[B >: A, C](f: B => IO[C])(implicit resource: Resource[B]) =
def using[C](f: A => IO[C])(implicit resource: Resource[A]) =
bracket(resource.close)(f)
}

@@ -241,7 +241,7 @@ trait IOFunctions extends IOStd {
* Register a finalizer in the current region. When the region terminates,
* all registered finalizers will be performed if they're not duplicated to a parent region.
*/
def onExit[S, P[+_] : MonadIO](finalizer: IO[Unit]):
def onExit[S, P[_] : MonadIO](finalizer: IO[Unit]):
RegionT[S, P, FinalizerHandle[({type λ[α] = RegionT[S, P, α]})#λ]] =
regionT(kleisli(hsIORef => (for {
refCntIORef <- newIORef(1)
@@ -257,7 +257,7 @@ trait IOFunctions extends IOStd {
* on exit if they haven't been duplicated themselves.
* The Forall quantifier prevents resources from being returned by this function.
*/
def runRegionT[P[+_] : MonadControlIO, A](r: Forall[({type λ[S] = RegionT[S, P, A]})#λ]): P[A] = {
def runRegionT[P[_] : MonadControlIO, A](r: Forall[({type λ[S] = RegionT[S, P, A]})#λ]): P[A] = {
def after(hsIORef: IORef[List[RefCountedFinalizer]]) = for {
hs <- hsIORef.read
_ <- hs.foldRight[IO[Unit]](IO.ioUnit) {
@@ -21,8 +21,8 @@ object MonadIO {
////

// TODO for some reason, putting this in RegionTInstances causes scalac to blow the stack
implicit def regionTMonadIO[S, M[+_]](implicit M0: MonadIO[M]) =
new MonadIO[({type λ[+α] = RegionT[S, M, α]})#λ] with RegionTLiftIO[S, M] with RegionTMonad[S, M] {
implicit def regionTMonadIO[S, M[_]](implicit M0: MonadIO[M]) =
new MonadIO[({type λ[α] = RegionT[S, M, α]})#λ] with RegionTLiftIO[S, M] with RegionTMonad[S, M] {
implicit def M = M0
implicit def L = M0
}
@@ -13,25 +13,25 @@ import Kleisli._
* to return an opened resource from the region, and no I/O with closed
* resources is possible.
*/
sealed trait RegionT[S, P[+_], +A] {
sealed trait RegionT[S, P[_], A] {
def value: Kleisli[P, IORef[List[RefCountedFinalizer]], A]

def runT(r: IORef[List[RefCountedFinalizer]]): P[A] =
value.run(r)
}

object RegionT extends RegionTFunctions with RegionTInstances {
def apply[S, P[+_], A](k: Kleisli[P, IORef[List[RefCountedFinalizer]], A]): RegionT[S, P, A] = new RegionT[S, P, A] {
def apply[S, P[_], A](k: Kleisli[P, IORef[List[RefCountedFinalizer]], A]): RegionT[S, P, A] = new RegionT[S, P, A] {
val value = k
}
}

trait RegionTInstances1 {
implicit def RegionTLiftIO[S, M[+_]](implicit M: LiftIO[M]): LiftIO[({type λ[α] = RegionT[S, M, α]})#λ] = new RegionTLiftIO[S, M] {
implicit def RegionTLiftIO[S, M[_]](implicit M: LiftIO[M]): LiftIO[({type λ[α] = RegionT[S, M, α]})#λ] = new RegionTLiftIO[S, M] {
implicit def L = M
}

implicit def RegionTMonad[S, M[+_]](implicit M0: Monad[M]): Monad[({type λ[α] = RegionT[S, M, α]})#λ] = new RegionTMonad[S, M] {
implicit def RegionTMonad[S, M[_]](implicit M0: Monad[M]): Monad[({type λ[α] = RegionT[S, M, α]})#λ] = new RegionTMonad[S, M] {
implicit def M = M0
}
}
@@ -40,18 +40,18 @@ trait RegionTInstances extends RegionTInstances1 {
}

trait RegionTFunctions {
def regionT[S, P[+_], A](k: Kleisli[P, IORef[List[RefCountedFinalizer]], A]): RegionT[S, P, A] = RegionT(k)
def regionT[S, P[_], A](k: Kleisli[P, IORef[List[RefCountedFinalizer]], A]): RegionT[S, P, A] = RegionT(k)
}

trait RegionTMonad[S, M[+_]] extends Monad[({type λ[α] = RegionT[S, M, α]})#λ] {
trait RegionTMonad[S, M[_]] extends Monad[({type λ[α] = RegionT[S, M, α]})#λ] {
implicit def M: Monad[M]

def point[A](a: => A): RegionT[S, M, A] = RegionT(kleisli(s => M.point(a)))
def bind[A, B](fa: RegionT[S, M, A])(f: A => RegionT[S, M, B]): RegionT[S, M, B] =
RegionT(kleisli(s => M.bind(fa.value.run(s))((a: A) => f(a).value.run(s))))
}

trait RegionTLiftIO[S, M[+_]] extends LiftIO[({type λ[α] = RegionT[S, M, α]})#λ] {
trait RegionTLiftIO[S, M[_]] extends LiftIO[({type λ[α] = RegionT[S, M, α]})#λ] {
implicit def L: LiftIO[M]

def liftIO[A](ioa: IO[A]) = RegionT.regionT(kleisli(_ => L.liftIO(ioa)))
@@ -4,22 +4,22 @@ package effect
object stateTEffect extends StateTEffectInstances

trait StateTEffectInstances0 extends StateTInstances {
implicit def StateTLiftIO[M[+_], S](implicit M0: MonadIO[M]): LiftIO[({type λ[+α] = StateT[M, S, α]})#λ] = new StateTLiftIO[M, S] {
implicit def StateTLiftIO[M[_], S](implicit M0: MonadIO[M]): LiftIO[({type λ[α] = StateT[M, S, α]})#λ] = new StateTLiftIO[M, S] {
implicit def M = M0
}
}

trait StateTEffectInstances extends StateTEffectInstances0 {
implicit def StateTMonadIO[M[+_], S](implicit M0: MonadIO[M]): MonadIO[({type λ[+α] = StateT[M, S, α]})#λ] = {
new MonadIO[({type λ[+α] = StateT[M, S, α]})#λ] with StateTLiftIO[M, S] with StateTMonadState[S, M] {
implicit def StateTMonadIO[M[_], S](implicit M0: MonadIO[M]): MonadIO[({type λ[α] = StateT[M, S, α]})#λ] = {
new MonadIO[({type λ[α] = StateT[M, S, α]})#λ] with StateTLiftIO[M, S] with StateTMonadState[S, M] {
implicit def F = M0
implicit def M = M0
}
}
}

trait StateTLiftIO[M[+_], S] extends LiftIO[({type λ[α] = StateT[M, S, α]})#λ] {
trait StateTLiftIO[M[_], S] extends LiftIO[({type λ[α] = StateT[M, S, α]})#λ] {
implicit def M: MonadIO[M]

def liftIO[A](ioa: IO[A]) = MonadTrans[({type λ[α[+_], +β] = StateT[α, S, β]})#λ].liftM(M.liftIO(ioa))
def liftIO[A](ioa: IO[A]) = MonadTrans[({type λ[α[_], β] = StateT[α, S, β]})#λ].liftM(M.liftIO(ioa))
}
@@ -5,11 +5,11 @@ import scalaz._
object StateTUsage extends App {
import StateT._

def f[M[+_]: Functor] {
def f[M[_]: Functor] {
Functor[({type l[a] = StateT[M, Int, a]})#l]
}

def m[M[+_]: Monad] {
def m[M[_]: Monad] {
Applicative[({type l[a] = StateT[M, Int, a]})#l]
Monad[({type l[a] = StateT[M, Int, a]})#l]
MonadState[({type f[s, a] = StateT[M, s, a]})#f, Int]
@@ -71,7 +71,8 @@ object TypelevelUsage extends App {
}

object Folding {

// https://github.com/scalaz/scalaz/issues/628
/*
import KLists._
object SomeCount extends HFold[Option, Int] {
@@ -89,7 +90,7 @@ object TypelevelUsage extends App {
val count2 = klist1.fold[Option, Int, HFold.Count[Option]](new HFold.Count[Option])
assert(count2 === 3)

*/
}

object ALists {
@@ -55,14 +55,15 @@ object build extends Build {
reapply(Seq(scalazMimaBasis in ThisBuild := releaseV), st)
}

val latestScala211PreRelease = "2.11.0-M7"
val latestScala211PreRelease = "2.11.0-M8"

lazy val standardSettings: Seq[Sett] = Defaults.defaultSettings ++ sbtrelease.ReleasePlugin.releaseSettings ++ Seq[Sett](
organization := "org.scalaz",

scalaVersion := "2.9.2",
crossScalaVersions := Seq("2.9.2", "2.9.3", "2.10.1", latestScala211PreRelease),
resolvers ++= (if (scalaVersion.value.endsWith("-SNAPSHOT")) List(Opts.resolver.sonatypeSnapshots) else Nil),
resolvers += Opts.resolver.sonatypeReleases,

scalaBinaryVersion in update := (
if (scalaVersion.value == "2.11.0-SNAPSHOT") latestScala211PreRelease else scalaBinaryVersion.value
@@ -365,7 +366,7 @@ object build extends Build {
object Dependencies {
def scalacheck(sv: String) =
if (sv startsWith "2.11")
"1.11.1"
"1.11.3"
else
"1.10.1"
}
@@ -17,15 +17,15 @@ object EitherTTest extends SpecLite {
checkAll(bitraverse.laws[EitherTList])

object instances {
def functor[F[+_] : Functor, A] = Functor[({type λ[α] = EitherT[F, A, α]})#λ]
def monad[F[+_] : Monad, A] = Monad[({type λ[α] = EitherT[F, A, α]})#λ]
def foldable[F[+_] : Foldable, A] = Foldable[({type λ[α] = EitherT[F, A, α]})#λ]
def traverse[F[+_] : Traverse, A] = Traverse[({type λ[α] = EitherT[F, A, α]})#λ]
def functor[F[_] : Functor, A] = Functor[({type λ[α] = EitherT[F, A, α]})#λ]
def monad[F[_] : Monad, A] = Monad[({type λ[α] = EitherT[F, A, α]})#λ]
def foldable[F[_] : Foldable, A] = Foldable[({type λ[α] = EitherT[F, A, α]})#λ]
def traverse[F[_] : Traverse, A] = Traverse[({type λ[α] = EitherT[F, A, α]})#λ]

// checking absence of ambiguity
def functor[F[+_] : Monad, A] = Functor[({type λ[α] = EitherT[F, A, α]})#λ]
def apply[F[+_] : Monad, A] = Apply[({type λ[α] = EitherT[F, A, α]})#λ]
def foldable[F[+_] : Traverse, A] = Foldable[({type λ[α] = EitherT[F, A, α]})#λ]
def functor[F[_] : Monad, A] = Functor[({type λ[α] = EitherT[F, A, α]})#λ]
def apply[F[_] : Monad, A] = Apply[({type λ[α] = EitherT[F, A, α]})#λ]
def foldable[F[_] : Traverse, A] = Foldable[({type λ[α] = EitherT[F, A, α]})#λ]
}

// compilation test
@@ -8,16 +8,16 @@ import std.AllInstances._
object IdTTest extends SpecLite {

object instances {
def functor[F[+_] : Functor] = Functor[({type λ[α] = IdT[F, α]})#λ]
def apply[F[+_] : Apply] = Apply[({type λ[α] = IdT[F, α]})#λ]
def monad[F[+_] : Monad] = Monad[({type λ[α] = IdT[F, α]})#λ]
def foldable[F[+_] : Foldable] = Foldable[({type λ[α] = IdT[F, α]})#λ]
def traverse[F[+_] : Traverse] = Traverse[({type λ[α] = IdT[F, α]})#λ]
def functor[F[_] : Functor] = Functor[({type λ[α] = IdT[F, α]})#λ]
def apply[F[_] : Apply] = Apply[({type λ[α] = IdT[F, α]})#λ]
def monad[F[_] : Monad] = Monad[({type λ[α] = IdT[F, α]})#λ]
def foldable[F[_] : Foldable] = Foldable[({type λ[α] = IdT[F, α]})#λ]
def traverse[F[_] : Traverse] = Traverse[({type λ[α] = IdT[F, α]})#λ]

// checking absence of ambiguity
def functor[F[+_] : Monad] = Functor[({type λ[α] = IdT[F, α]})#λ]
def functor[F[+_] : Monad : Traverse] = Functor[({type λ[α] = IdT[F, α]})#λ]
def apply[F[+_] : Monad] = Apply[({type λ[α] = IdT[F, α]})#λ]
def foldable[F[+_] : Traverse] = Foldable[({type λ[α] = IdT[F, α]})#λ]
def functor[F[_] : Monad] = Functor[({type λ[α] = IdT[F, α]})#λ]
def functor[F[_] : Monad : Traverse] = Functor[({type λ[α] = IdT[F, α]})#λ]
def apply[F[_] : Monad] = Apply[({type λ[α] = IdT[F, α]})#λ]
def foldable[F[_] : Traverse] = Foldable[({type λ[α] = IdT[F, α]})#λ]
}
}
@@ -18,7 +18,7 @@ object KleisliTest extends SpecLite {
(3, A.arbitrary.map(a => (_: Int) => a))
))

implicit def KleisliEqual[M[+_]](implicit M: Equal[M[Int]]): Equal[Kleisli[M, Int, Int]] = new Equal[Kleisli[M, Int, Int]] {
implicit def KleisliEqual[M[_]](implicit M: Equal[M[Int]]): Equal[Kleisli[M, Int, Int]] = new Equal[Kleisli[M, Int, Int]] {
def equal(a1: Kleisli[M, Int, Int], a2: Kleisli[M, Int, Int]): Boolean = {
val mb1: M[Int] = a1.run(0)
val mb2: M[Int] = a2.run(0)
@@ -36,23 +36,23 @@ object KleisliTest extends SpecLite {
checkAll(category.laws[KleisliOpt])

object instances {
def semigroup[F[+_], A, B](implicit FB: Semigroup[F[B]]) = Semigroup[Kleisli[F, A, B]]
def monoid[F[+_], A, B](implicit FB: Monoid[F[B]]) = Monoid[Kleisli[F, A, B]]
def functor[F[+_] : Functor, A] = Functor[({type f[a] = Kleisli[F, A, a]})#f]
def apply[F[+_] : Apply, A] = Apply[({type f[a] = Kleisli[F, A, a]})#f]
def plus[F[+_] : Plus, A] = Plus[({type f[a] = Kleisli[F, A, a]})#f]
def empty[F[+_] : PlusEmpty, A] = PlusEmpty[({type f[a] = Kleisli[F, A, a]})#f]
def monadReader[F[+_] : Monad, A] = MonadReader[({type f[s, a] = Kleisli[F, s, a]})#f, A]
def semigroup[F[_], A, B](implicit FB: Semigroup[F[B]]) = Semigroup[Kleisli[F, A, B]]
def monoid[F[_], A, B](implicit FB: Monoid[F[B]]) = Monoid[Kleisli[F, A, B]]
def functor[F[_] : Functor, A] = Functor[({type f[a] = Kleisli[F, A, a]})#f]
def apply[F[_] : Apply, A] = Apply[({type f[a] = Kleisli[F, A, a]})#f]
def plus[F[_] : Plus, A] = Plus[({type f[a] = Kleisli[F, A, a]})#f]
def empty[F[_] : PlusEmpty, A] = PlusEmpty[({type f[a] = Kleisli[F, A, a]})#f]
def monadReader[F[_] : Monad, A] = MonadReader[({type f[s, a] = Kleisli[F, s, a]})#f, A]

def category[F[+_]: Monad, A] = Category[({type λ[α, β]=Kleisli[F, α, β]})#λ]
def arrow[F[+_]: Monad, A] = Arrow[({type λ[α, β]=Kleisli[F, α, β]})#λ]
def category[F[_]: Monad, A] = Category[({type λ[α, β]=Kleisli[F, α, β]})#λ]
def arrow[F[_]: Monad, A] = Arrow[({type λ[α, β]=Kleisli[F, α, β]})#λ]

// checking absence of ambiguity
def semigroup[F[+_], A, B](implicit FB: Monoid[F[B]]) = Semigroup[Kleisli[F, A, B]]
def functor[F[+_] : Monad, A] = Functor[({type f[a] = Kleisli[F, A, a]})#f]
def apply[F[+_] : Monad, A] = Apply[({type f[a] = Kleisli[F, A, a]})#f]
def plus[F[+_] : PlusEmpty, A] = Plus[({type f[a] = Kleisli[F, A, a]})#f]
def empty[F[+_] : MonadPlus, A] = PlusEmpty[({type f[a] = Kleisli[F, A, a]})#f]
def semigroup[F[_], A, B](implicit FB: Monoid[F[B]]) = Semigroup[Kleisli[F, A, B]]
def functor[F[_] : Monad, A] = Functor[({type f[a] = Kleisli[F, A, a]})#f]
def apply[F[_] : Monad, A] = Apply[({type f[a] = Kleisli[F, A, a]})#f]
def plus[F[_] : PlusEmpty, A] = Plus[({type f[a] = Kleisli[F, A, a]})#f]
def empty[F[_] : MonadPlus, A] = PlusEmpty[({type f[a] = Kleisli[F, A, a]})#f]

object reader {
// F = Id
@@ -13,7 +13,7 @@ object LazyEitherTTest extends SpecLite {
Equal[Either[A, B]].equal(a.toEither,b.toEither)
}

implicit def lazyEitherTEqual[F[+_], A, B](implicit F0: Equal[F[LazyEither[A, B]]]): Equal[LazyEitherT[F, A, B]] =
implicit def lazyEitherTEqual[F[_], A, B](implicit F0: Equal[F[LazyEither[A, B]]]): Equal[LazyEitherT[F, A, B]] =
F0.contramap((_: LazyEitherT[F, A, B]).run)

type LazyEitherTList[A, B] = LazyEitherT[List, A, B]
@@ -13,11 +13,11 @@ object LazyOptionTTest extends SpecLite {
checkAll(monad.laws[LazyOptionTList])

object instances {
def functor[F[+_] : Functor] = Functor[({type λ[α] = LazyOptionT[F, α]})#λ]
def monad[F[+_] : Monad] = Monad[({type λ[α] = LazyOptionT[F, α]})#λ]
def functor[F[_] : Functor] = Functor[({type λ[α] = LazyOptionT[F, α]})#λ]
def monad[F[_] : Monad] = Monad[({type λ[α] = LazyOptionT[F, α]})#λ]

// checking absence of ambiguity
def functor[F[+_] : Monad] = Functor[({type λ[α] = LazyOptionT[F, α]})#λ]
def apply[F[+_] : Monad] = Apply[({type λ[α] = LazyOptionT[F, α]})#λ]
def functor[F[_] : Monad] = Functor[({type λ[α] = LazyOptionT[F, α]})#λ]
def apply[F[_] : Monad] = Apply[({type λ[α] = LazyOptionT[F, α]})#λ]
}
}
@@ -61,12 +61,12 @@ object ListTTest extends SpecLite {
checkAll(monadPlus.laws[ListTOpt])

object instances {
def semigroup[F[+_]: Monad, A] = Semigroup[ListT[F, A]]
def monoid[F[+_]: Monad, A] = Monoid[ListT[F, A]]
def monad[F[+_]: Monad, A] = Monad[({type λ[α]=ListT[F, α]})#λ]
def functor[F[+_]: Functor, A] = Functor[({type λ[α]=ListT[F, α]})#λ]
def semigroup[F[_]: Monad, A] = Semigroup[ListT[F, A]]
def monoid[F[_]: Monad, A] = Monoid[ListT[F, A]]
def monad[F[_]: Monad, A] = Monad[({type λ[α]=ListT[F, α]})#λ]
def functor[F[_]: Functor, A] = Functor[({type λ[α]=ListT[F, α]})#λ]

// checking absence of ambiguity
def functor[F[+_]: Monad, A] = Functor[({type λ[α]=ListT[F, α]})#λ]
def functor[F[_]: Monad, A] = Functor[({type λ[α]=ListT[F, α]})#λ]
}
}
@@ -15,15 +15,15 @@ object OptionTTest extends SpecLite {
checkAll(traverse.laws[OptionTList])

object instances {
def functor[F[+_] : Functor] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def monad[F[+_] : Monad] = MonadPlus[({type λ[α] = OptionT[F, α]})#λ]
def foldable[F[+_] : Foldable] = Foldable[({type λ[α] = OptionT[F, α]})#λ]
def traverse[F[+_] : Traverse] = Traverse[({type λ[α] = OptionT[F, α]})#λ]
def functor[F[_] : Functor] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def monad[F[_] : Monad] = MonadPlus[({type λ[α] = OptionT[F, α]})#λ]
def foldable[F[_] : Foldable] = Foldable[({type λ[α] = OptionT[F, α]})#λ]
def traverse[F[_] : Traverse] = Traverse[({type λ[α] = OptionT[F, α]})#λ]

// checking absence of ambiguity
def functor[F[+_] : Monad] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def functor[F[+_] : Monad : Traverse] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def apply[F[+_] : Monad] = Apply[({type λ[α] = OptionT[F, α]})#λ]
def foldable[F[+_] : Traverse] = Foldable[({type λ[α] = OptionT[F, α]})#λ]
def functor[F[_] : Monad] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def functor[F[_] : Monad : Traverse] = Functor[({type λ[α] = OptionT[F, α]})#λ]
def apply[F[_] : Monad] = Apply[({type λ[α] = OptionT[F, α]})#λ]
def foldable[F[_] : Traverse] = Foldable[({type λ[α] = OptionT[F, α]})#λ]
}
}
@@ -30,12 +30,12 @@ object ReaderWriterStateTTest extends SpecLite {
checkAll(monad.laws[RWSOptInt])

object instances {
def functor[F[+_]: Functor, R, W, S] = Functor[({type λ[+α]=RWST[F, R, W, S, α]})#λ]
def monad[F[+_]: Monad, R, W: Monoid, S] = Monad[({type λ[+α]=RWST[F, R, W, S, α]})#λ]
def monadReader[F[+_]: Monad, R, W: Monoid, S] = MonadReader[({type λ[-r, +α]=RWST[F, r, W, S, α]})#λ, R]
def monadState[F[+_]: Monad, R, W: Monoid, S] = MonadState[({type λ[s, +α]=RWST[F, R, W, s, α]})#λ, S]
def monadTrans[R, W: Monoid, S] = MonadTrans[({type λ[f[+_], α]=RWST[f, R, W, S, α]})#λ]
def functor[F[_]: Functor, R, W, S] = Functor[({type λ[α]=RWST[F, R, W, S, α]})#λ]
def monad[F[_]: Monad, R, W: Monoid, S] = Monad[({type λ[α]=RWST[F, R, W, S, α]})#λ]
def monadReader[F[_]: Monad, R, W: Monoid, S] = MonadReader[({type λ[-r, α]=RWST[F, r, W, S, α]})#λ, R]
def monadState[F[_]: Monad, R, W: Monoid, S] = MonadState[({type λ[s, α]=RWST[F, R, W, s, α]})#λ, S]
def monadTrans[R, W: Monoid, S] = MonadTrans[({type λ[f[_], α]=RWST[f, R, W, S, α]})#λ]
// checking absence of ambiguity
def functor[F[+_]: Monad, R, W: Monoid, S] = Functor[({type λ[+α]=RWST[F, R, W, S, α]})#λ]
def functor[F[_]: Monad, R, W: Monoid, S] = Functor[({type λ[α]=RWST[F, R, W, S, α]})#λ]
}
}
@@ -20,14 +20,14 @@ object StateTTest extends SpecLite {
checkAll(monad.laws[StateTListInt])

object instances {
def functor[S, F[+_] : Functor] = Functor[({type λ[+α] = StateT[F, S, α]})#λ]
def monadState[S, F[+_] : Monad] = MonadState[({type λ[α, +β]=StateT[F, α, β]})#λ, S]
def functor[S, F[_] : Functor] = Functor[({type λ[α] = StateT[F, S, α]})#λ]
def monadState[S, F[_] : Monad] = MonadState[({type λ[α, β]=StateT[F, α, β]})#λ, S]

// F = Id
def functor[S] = Functor[({type λ[α] = State[S, α]})#λ]
def monadState[S] = MonadState[({type λ[α, β]=State[α, β]})#λ, S]

// checking absence of ambiguity
def functor[S, F[+_] : Monad] = Functor[({type λ[+α] = StateT[F, S, α]})#λ]
def functor[S, F[_] : Monad] = Functor[({type λ[α] = StateT[F, S, α]})#λ]
}
}
@@ -17,13 +17,13 @@ object StoreTTest extends SpecLite {

object instances {
type A = Int
def functor[F[+_] : Functor] = Functor[({type λ[+α] = StoreT[F, A, α]})#λ]
def cobind[F[+_] : Cobind] = Cobind[({type λ[+α] = StoreT[F, A, α]})#λ]
def comonad[F[+_] : Comonad] = Comonad[({type λ[+α] = StoreT[F, A, α]})#λ]
def functor[F[_] : Functor] = Functor[({type λ[α] = StoreT[F, A, α]})#λ]
def cobind[F[_] : Cobind] = Cobind[({type λ[α] = StoreT[F, A, α]})#λ]
def comonad[F[_] : Comonad] = Comonad[({type λ[α] = StoreT[F, A, α]})#λ]

// checking absence of ambiguity
def functor[F[+_] : Comonad] = Functor[({type λ[+α] = StoreT[F, A, α]})#λ]
def cobind[F[+_] : Comonad] = Cobind[({type λ[+α] = StoreT[F, A, α]})#λ]
def functor[F[_] : Comonad] = Functor[({type λ[α] = StoreT[F, A, α]})#λ]
def cobind[F[_] : Comonad] = Cobind[({type λ[α] = StoreT[F, A, α]})#λ]
}

}
@@ -55,9 +55,9 @@ object StreamTTest extends SpecLite {
checkAll(monadPlus.laws[StreamTOpt])

object instances {
def semigroup[F[+_]: Functor, A] = Semigroup[StreamT[F, A]]
def monoid[F[+_]: Applicative, A] = Monoid[StreamT[F, A]]
def functor[F[+_]: Functor, A] = Functor[({type λ[α]=StreamT[F, α]})#λ]
def monad[F[+_]: Monad, A] = Monad[({type λ[α]=StreamT[F, α]})#λ]
def semigroup[F[_]: Functor, A] = Semigroup[StreamT[F, A]]
def monoid[F[_]: Applicative, A] = Monoid[StreamT[F, A]]
def functor[F[_]: Functor, A] = Functor[({type λ[α]=StreamT[F, α]})#λ]
def monad[F[_]: Monad, A] = Monad[({type λ[α]=StreamT[F, α]})#λ]
}
}
@@ -18,33 +18,33 @@ object WriterTTest extends SpecLite {
checkAll(monad.laws[WriterTOptInt])
checkAll(traverse.laws[WriterTOptInt])
checkAll(bifunctor.laws[WriterTOpt])
checkAll(functor.laws[({type λ[+α]=WriterT[NonEmptyList, Int, α]})#λ])
checkAll(functor.laws[({type λ[α]=WriterT[NonEmptyList, Int, α]})#λ])
checkAll(bitraverse.laws[WriterTOpt])

implicit def writerArb[F[+_], W, A](implicit W: Arbitrary[W], A: Arbitrary[A]): Arbitrary[Writer[W, A]] =
implicit def writerArb[F[_], W, A](implicit W: Arbitrary[W], A: Arbitrary[A]): Arbitrary[Writer[W, A]] =
Applicative[Arbitrary].apply2(W, A)((w, a) => Writer[W, A](w, a))

checkAll(comonad.laws[({type λ[+α]=Writer[Int, α]})#λ])
checkAll(comonad.laws[({type λ[α]=Writer[Int, α]})#λ])

object instances {
def functor[F[+_]: Functor, W] = Functor[({type λ[+α]=WriterT[F, W, α]})#λ]
def apply[F[+_]: Monad, W: Semigroup] = Apply[({type λ[+α]=WriterT[F, W, α]})#λ]
def monad[F[+_]: Monad, W: Monoid] = Monad[({type λ[+α]=WriterT[F, W, α]})#λ]
def foldable[F[+_]: Foldable, W] = Foldable[({type λ[+α]=WriterT[F, W, α]})#λ]
def traverse[F[+_]: Traverse, W] = Traverse[({type λ[+α]=WriterT[F, W, α]})#λ]

def functor[F[+_]: Monad, W: Monoid] = Functor[({type λ[+α]=WriterT[F, W, α]})#λ]
def apply[F[+_]: Monad, W: Monoid] = Apply[({type λ[+α]=WriterT[F, W, α]})#λ]
def functor[F[+_]: Traverse, W: Monoid] = Functor[({type λ[+α]=WriterT[F, W, α]})#λ]
def foldable[F[+_]: Traverse, W] = Foldable[({type λ[+α]=WriterT[F, W, α]})#λ]
def functor[F[_]: Functor, W] = Functor[({type λ[α]=WriterT[F, W, α]})#λ]
def apply[F[_]: Monad, W: Semigroup] = Apply[({type λ[α]=WriterT[F, W, α]})#λ]
def monad[F[_]: Monad, W: Monoid] = Monad[({type λ[α]=WriterT[F, W, α]})#λ]
def foldable[F[_]: Foldable, W] = Foldable[({type λ[α]=WriterT[F, W, α]})#λ]
def traverse[F[_]: Traverse, W] = Traverse[({type λ[α]=WriterT[F, W, α]})#λ]

def functor[F[_]: Monad, W: Monoid] = Functor[({type λ[α]=WriterT[F, W, α]})#λ]
def apply[F[_]: Monad, W: Monoid] = Apply[({type λ[α]=WriterT[F, W, α]})#λ]
def functor[F[_]: Traverse, W: Monoid] = Functor[({type λ[α]=WriterT[F, W, α]})#λ]
def foldable[F[_]: Traverse, W] = Foldable[({type λ[α]=WriterT[F, W, α]})#λ]

object writer {
def functor[W] = Functor[({type λ[+α]=Writer[W, α]})#λ]
def apply[W: Semigroup] = Apply[({type λ[+α]=Writer[W, α]})#λ]
def monad[W: Monoid] = Monad[({type λ[+α]=Writer[W, α]})#λ]
def foldable[W] = Foldable[({type λ[+α]=Writer[W, α]})#λ](WriterT.writerTFoldable[Id, W])
def traverse[W] = Traverse[({type λ[+α]=Writer[W, α]})#λ]
def comonad[W] = Comonad[({type λ[+α]=Writer[W, α]})#λ]
def functor[W] = Functor[({type λ[α]=Writer[W, α]})#λ]
def apply[W: Semigroup] = Apply[({type λ[α]=Writer[W, α]})#λ]
def monad[W: Monoid] = Monad[({type λ[α]=Writer[W, α]})#λ]
def foldable[W] = Foldable[({type λ[α]=Writer[W, α]})#λ](WriterT.writerTFoldable[Id, W])
def traverse[W] = Traverse[({type λ[α]=Writer[W, α]})#λ]
def comonad[W] = Comonad[({type λ[α]=Writer[W, α]})#λ]
}
}
}