Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created December 12, 2013 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/7937745 to your computer and use it in GitHub Desktop.
Save xuwei-k/7937745 to your computer and use it in GitHub Desktop.
package scalaz
abstract class Density[F[_], A]{ self =>
def apply[B](g: F[B] => A)(h: F[B]): Density[F, A]
// fmap f (Density g h) = Density (f . g) h
def map[B](f: A => B): Density[F, B] =
new Density[F, B] {
def apply[C](x: F[C] => B)(fc: F[C]): Density[F, B] = {
???
}
}
def cobind[B](f: Density[F, A] => B): Density[F, B] =
???
}
sealed abstract class DensityInstances2 {
implicit def densityApply[F[_]: Apply]: Apply[({type λ[α] = Density[F, α]})#λ] =
new DensityApply[F] {
def F = implicitly
}
}
sealed abstract class DensityInstances1 extends DensityInstances2{
implicit def densityApplicative[F[_]: Applicative]: Applicative[({type λ[α] = Density[F, α]})#λ] =
new DensityApplicative[F] {
def F = implicitly
}
}
sealed abstract class DensityInstances extends DensityInstances1 {
implicit def densityInstance[F[_]]: Comonad[({type λ[α] = Density[F, α]})#λ] =
new Comonad[({type λ[α] = Density[F, α]})#λ] with DensityFunctor[F] {
def cobind[A, B](fa: Density[F, A])(f: Density[F, A] => B) =
fa cobind f
def copoint[A](fa: Density[F, A]): A =
???
}
}
object Density extends DensityInstances{
}
private trait DensityFunctor[F[_]] extends Functor[({type λ[α] = Density[F, α]})#λ] {
override final def map[A, B](fa: Density[F, A])(f: A => B) =
fa map f
}
private trait DensityApply[F[_]]
extends Apply[({type λ[α] = Density[F, α]})#λ]
with DensityFunctor[F] {
implicit def F: Apply[F]
// TODO
// Density kxf x <.> Density kya y =
// Density (\k -> kxf (fmap fst k) (kya (fmap snd k))) ((,) <$> x <.> y)
def ap[A, B](fa: => Density[F, A])(f: => Density[F, A => B]): Density[F, B] =
new Density[F, B] {
def apply[C](f: F[C] => B)(fc: F[C]) =
???
}
}
private trait DensityApplicative[F[_]]
extends Applicative[({type λ[α] = Density[F, α]})#λ]
with DensityApply[F] {
def F: Applicative[F]
override final def point[A](a: => A): Density[F, A] =
new Density[F, A] {
def apply[B](f: F[B] => A)(fb: F[B]): Density[F, A] = {
// TODO
// pure a = Density (const a) (pure ())
???
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment