forked from scalaz/scalaz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type classes: expose super class functions in sub classes. (WIP)
Also ensure inheritance-based implementations via seal of type class. This avoid going through no-op invoke virtuals in most cases. WIP: Monoid/Semigroup/Functor->Monad only.
- Loading branch information
Showing
39 changed files
with
282 additions
and
265 deletions.
There are no files selected for viewing
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
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
57 changes: 34 additions & 23 deletions
57
base/shared/src/main/scala/scalaz/data/ConstInstances.scala
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
4 changes: 1 addition & 3 deletions
4
base/shared/src/main/scala/scalaz/data/DisjunctionInstances.scala
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
6 changes: 2 additions & 4 deletions
6
base/shared/src/main/scala/scalaz/data/IdentityInstances.scala
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
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
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
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
24 changes: 20 additions & 4 deletions
24
base/shared/src/main/scala/scalaz/typeclass/Applicative.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
package scalaz | ||
package typeclass | ||
|
||
trait Applicative[F[_]] { | ||
def apply: Apply[F] | ||
def pure[A](a: A): F[A] | ||
} | ||
sealed trait Applicative[F[_]] extends Applicative.Class[F] | ||
|
||
object Applicative { | ||
|
||
trait Class[F[_]] extends Apply.Class[F] { | ||
def pure[A](a: A): F[A] | ||
|
||
def applicative: Applicative[F] | ||
} | ||
|
||
trait Template[F[_]] extends Apply.Template[F] with Applicative[F] { | ||
final override def applicative = this | ||
} | ||
|
||
trait DeriveMap[F[_]] extends Monad.Alt[DeriveMap[F]] { self: Class[F] => | ||
final override def map[A, B](ma: F[A])(f: (A) => B): F[B] = ap(ma)(pure(f)) | ||
} | ||
|
||
def apply[F[_]](implicit F: Applicative[F]): Applicative[F] = F | ||
} |
14 changes: 0 additions & 14 deletions
14
base/shared/src/main/scala/scalaz/typeclass/ApplicativeClass.scala
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package scalaz | ||
package typeclass | ||
|
||
trait Apply[F[_]] { | ||
def functor: Functor[F] | ||
def ap[A, B](fa: F[A])(f: F[A => B]): F[B] | ||
} | ||
sealed trait Apply[F[_]] extends Apply.Class[F] | ||
|
||
object Apply { | ||
|
||
trait Class[F[_]] extends Functor.Class[F] { | ||
def ap[A, B](fa: F[A])(f: F[A => B]): F[B] | ||
|
||
def apply: Apply[F] | ||
} | ||
|
||
trait Template[F[_]] extends Functor.Template[F] with Apply[F] { | ||
final override def apply = this | ||
} | ||
|
||
def apply[F[_]](implicit F: Apply[F]): Apply[F] = F | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
package scalaz | ||
package typeclass | ||
|
||
trait Bind[M[_]] { | ||
def apply: Apply[M] | ||
def flatMap[A, B](ma: M[A])(f: A => M[B]): M[B] | ||
def flatten[A](ma: M[M[A]]): M[A] | ||
} | ||
sealed trait Bind[M[_]] extends Bind.Class[M] | ||
|
||
object Bind { | ||
|
||
trait Class[M[_]] extends Apply.Class[M] { | ||
def flatMap[A, B](ma: M[A])(f: A => M[B]): M[B] | ||
def flatten[A](ma: M[M[A]]): M[A] | ||
|
||
def bind: Bind[M] | ||
} | ||
|
||
trait Template[M[_]] extends Apply.Template[M] with Bind[M] { | ||
final override def bind = this | ||
} | ||
|
||
trait DeriveAp[M[_]] extends Monad.Alt[DeriveAp[M]] { self: Class[M] => | ||
final override def ap[A, B](fa: M[A])(f: M[A => B]): M[B] = flatMap(f)(map(fa)) | ||
} | ||
|
||
trait Alt[D <: Alt[D]] | ||
trait DeriveFlatten[M[_]] extends Alt[DeriveFlatten[M]] { self: Class[M] => | ||
final override def flatten[A](ma: M[M[A]]): M[A] = flatMap(ma)(identity) | ||
} | ||
trait DeriveFlatMap[M[_]] extends Alt[DeriveFlatMap[M]] { self: Class[M] => | ||
final override def flatMap[A, B](ma: M[A])(f: (A) => M[B]): M[B] = flatten(map(ma)(f)) | ||
} | ||
|
||
def apply[F[_]](implicit F: Bind[F]): Bind[F] = F | ||
} |
Oops, something went wrong.