Skip to content

Instantly share code, notes, and snippets.

@nuttycom
Last active December 18, 2015 08:09
Show Gist options
  • Save nuttycom/5751479 to your computer and use it in GitHub Desktop.
Save nuttycom/5751479 to your computer and use it in GitHub Desktop.
A hypothesis as to what functors, monads, etc. might look like if the value type were not universally quantified, but instead could be restricted by requirement for other typeclass instances. Universal quantification could still be achieved, of course; hence this provides a more flexible generalization of our familiar typeclasses. This grew out …
trait Functorial[F[_], B] {
def map[A](m: F[A])(f: A => B): F[B]
}
trait Monadic[M[_], B] extends Functorial[F, B] {
def point(b: B): M[B]
def flatMap[A](m: M[A])(f: A => M[B]): M[B]
}
trait Traversial[F[_], B] {
def traverse[G[_], A](m: F[A])(f: A => G[B]): G[F[B]]
}
object SetFunctorial {
sealed trait SetConstruction[A]
case class HashSetConstruction[A](eql: Equal[A], hsh: Hashable[A]) extends SetConstruction[A]
case class TreeSetConstruaction[A](ord: Order[A]) extends SetConstruction[A]
implicit def setEqual(s: Set[A]) = new Equal[A] {
def equal(a0: A, a1: A) = (s + a0).contains(a1)
}
implicit def setFunctorial[B: SetConstruction]: Functorial[Set, B] = new Functorial[Set, B] {
def map[A](m: Set[A])(f: A => B): Set[B] = {
sys.error("todo")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment