Skip to content

Instantly share code, notes, and snippets.

trait P1[T]
final class C1(x: Int) extends P1[Int]
val v = (C1(1): P1[]
trait P2[T, U]
final class C2_3[A, B](x: A, y: B) extends P2[A, B]
final class C2_2[A, B](x: A, y: B) extends P2[B, A]
member(T, s1(T), s0).
member(L, s2(L, R), s1(R)).
member(L, s3(L, M, R), s2(M, R)).
member(T, ss(s1(T), s3(L, M, R)), s3(L, M, R)).
member(L, ss(s1(T), s3(L, M, R)), s3(T, M, R)).
member(M, ss(s1(T), s3(L, M, R)), s3(T, L, R)).
member(R, ss(s1(T), s3(L, M, R)), s3(T, L, M)).
member(T1, ss(s2(T1, T2), R), ss(s1(T2), R)).
member(T2, ss(s2(T1, T2), R), ss(s1(T1), R)).
@sir-wabbit
sir-wabbit / TypeSet.scala
Created September 2, 2016 05:20
TypeSet.scala
package sio.eff
import TypeSet._
sealed trait TypeSet[E]
object TypeSet {
trait S0[E ] extends TypeSet[E]
trait S1[E, E1 <: E ] extends TypeSet[E]
trait S2[E, E1 <: E, E2 <: E ] extends TypeSet[E]
trait S3[E, E1 <: E, E2 <: E, E3 <: E ] extends TypeSet[E]
trait TMonad[F[_, _]] {
type State[S]
type Compose[_, _, _]
def pure[I, A](a: A)(implicit I: State[I]): F[I, A]
def map[S, A, B](fa: F[S, A])(f: A => B): F[S, B]
def ap[S1, S2, S, A, B](f: F[S1, A => B])(fa: F[S2, A])(implicit S: Compose[S1, S2, S]): F[S, B]
def flatMap[S1, S2, S, A, B](fa: F[S1, A])(f: A => F[S2, B])(implicit S: Compose[S1, S2, S]): F[S, B]
}
object TMonad {
import cats.Id
import scala.annotation.tailrec
import scala.reflect.ClassTag
trait Module[ST[_, _]] {
protected def captureEffect[S, A](a: => A): ST[S, A]
final class STArrayQueue[S, T] private (
private var data: Array[T],
import cats.{Applicative, Monad}
import cats.kernel.Monoid
object QuantifiedContexts {
trait Forall[F[_]] { def apply[A]: F[A] }
trait Exists[F[_]] { type A; def apply: F[A] }
type MonoidK[F[_]] = Forall[λ[X => Monoid[F[X]]]]
final case class Alternative[F[_]](applicative: Applicative[F], monoid: MonoidK[F])
object Forall {
trait Forall[F[_]] { def apply[A]: F[A] }
trait Forall2[F[_, _]] { def apply[A, B]: F[A, B] }
type ~>[F[_], G[_]] = Forall[ λ[ A => F[A] => G[A]]]
type ~~>[F[_, _], G[_, _]] = Forall2[λ[(A, B) => F[A, B] => G[A, B]]]
type Id[A] = A
type Hom[F[_], A, B] = F[A] => F[B]
type Prod[F[_], G[_], A, B] = F[(G[A], G[B])]
type Unit = scala.Unit
object Unit {
type K1[_] = Unit
type K2[_, _] = Unit
type KK1[_[_]] = Unit
implicit val trivial: Unit = ()
}
type Nothing = scala.Nothing
trait RMonad[I[_], F[_]] {
def pure[A](ja: I[A]): F[A]
def flatMap[A, B](ma: F[A])(f: I[A] => F[B]): F[B]
}
object RMonad {
import cats.MonadError
implicit def monadError0[E, F[_]](F: MonadError[F, E]): RMonad[Either[E, ?], F] =
new RMonad[Either[E, ?], F] {
def pure[A](ja: Either[E, A]): F[A] = ja match {
sealed abstract class TypeF protected() {
type F[A]
def F: Functor[F]
}
object TypeF {
sealed abstract class Aux[F_[_]] extends TypeF {
type F[A] = F_[A]
def F: Functor[F]
}