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
trait DepFunction1[T]{ self => | |
type R | |
def apply(t: T): R | |
def andThen(dep: DepFunction1[R]): Aux[T, dep.R] = new DepFunction1[T]{ | |
type R = dep.R | |
def apply(t: T) = dep(self(t)) | |
} |
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
trait IsNotFuture[+F] | |
object IsNotFuture{ | |
def apply[F](implicit isf: IsNotFuture[F]) = isf | |
implicit def mkFuture[A] = new IsNotFuture[Future[A]] {} | |
implicit object isf extends IsNotFuture[Any] {} | |
} | |
//No need for a dependent type. All you need is the implicit ambiguity. |
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
trait Or[X <: Boolean, Y <: Boolean]{ | |
type Out <: Boolean | |
def value: bool | |
} | |
object Or extends LowPriorityOr{ | |
def apply[X <: Boolean, Y <: Boolean](implicit or: Or[X, Y]): Aux[X, Y, or.Out] = or | |
implicit object OrFalse extends Or[False, False]{ |
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
trait IsBase[F]{ | |
type T | |
type W[X] | |
def to(f: F): W[T] | |
def from(wt: W[T]): F | |
def apply(f: F): W[T] = to(f) | |
} |
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
sealed trait TList | |
case object TNil extends TList | |
case class <+>[A, B <: TList]() extends TList //some weird symbol for :: | |
trait Contains[A, TL <: TList] | |
object Contains extends LowPriorityContains{ | |
def apply[A, TL <: TList](implicit cnt: Contains[A, TL]) = cnt | |
implicit def has[F[_], A, T <: TList] = new Contains[F, F[A] <+> T]{} |
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 even reasonably useable? | |
implicit class AddPost[T, R](f: T => R){ | |
def withPostCondition(pred: R => Boolean) = {x: T => | |
val out = f(x) | |
if(pred(out)) out else throw new MatchException("Did not satisfy post condition") | |
} | |
} |
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
import shapeless._ | |
import poly._ | |
trait Next[T]{ | |
type R <: Trampoline | |
def apply(t: T): R | |
} | |
object Next{ | |
def apply[T](implicit nxt: Next[T]): Aux[T, nxt.R] = nxt |
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
//for reference | |
trait Cont[T, R]{ self => | |
def apply(f: T => R): R | |
def map[B](f: T => B): Cont[B, R] = new Cont[B, R]{ | |
def apply(g: B => R): R = self(f andThen g) | |
} |
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
//alright, not completely perfect but getting close enough | |
//Still relying too heavily on Aux types to tie type knots | |
trait DepState[S]{ self => | |
type R | |
def apply(s: S): (S, R) | |
def map(f: DepFun1[R]): DepState[S] = new DepState[S]{ | |
type R = f.R | |
def apply(s: S): (S, f.R) ={ |
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
/* | |
So here's the error which seems to be straight forward. That said, I've tried a bunch of things and this is the "bets" I've been | |
able to do: | |
[error] CKnot.scala:18: Cannot construct a collection of type That with elements of type B based on a collection of type C[A]. | |
[error] def apply[A, C[A] <: GenTraversableLike[A, C[A]]](ma: C[A], f: A => C[B]) = ma flatMap f | |
[error] | |
[error] CKnot.scala:26: Cannot construct a collection of type That with elements of type B based on a collection of type C[A]. | |
[error] a <- ma | |
[error] |