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 X[A <: AnyKind, F[_ <: AnyKind]] { type B = F[A] } | |
// OK | |
val i5: X[Option, ({ type l[X[_]] = X[Int] })#l]#B = Some(5) | |
///////////////////////////////////////////////////////////// | |
// KO | |
val i1: X[Option, List]#B = Some(5) | |
// Error Before Patch |
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 Monoid[M <: AnyKind] { | |
type ->[_<:AnyKind, _<:AnyKind] | |
type I <: AnyKind | |
def unit: ->[I, M] | |
def mult(a: I -> M, b: I -> M): I -> M | |
} | |
object Monoid { | |
type Aux[M <: AnyKind, M0[_<:AnyKind, _<:AnyKind], I0 <: AnyKind] = Monoid[M] { type ->[a <: AnyKind, b <: AnyKind] = M0[a, b]; type I = I0 } |
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
object Test extends App { | |
implicit val b: String = "toto" | |
implicit val c: Float = 1.0F | |
trait Foo[A] { | |
type B | |
def AtoB(a: A): B | |
} |
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
// WARNING... NOT FOR THE FAINT HEARTED | |
// Scala Conversion of haskell code in http://blog.functorial.com/posts/2012-02-02-Polykinded-Folds.html | |
// to study more samples of kind polymorphism in Scala | |
// | |
// It provides the implementation of Kind-Polymorphism Category, Functor & Rec for generic folding | |
// HASKELL CODE | |
// class Category hom where | |
// ident :: hom a a | |
// compose :: hom a b -> hom b c -> hom a c |
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
/** Showing with Kind-Polymorphism the evidence that Monad is a monoid in the category of endofunctors */ | |
object Test extends App { | |
/** Monoid (https://en.wikipedia.org/wiki/Monoid_(category_theory)) | |
* In category theory, a monoid (or monoid object) (M, μ, η) in a monoidal category (C, ⊗, I) | |
* is an object M together with two morphisms | |
* | |
* μ: M ⊗ M → M called multiplication, | |
* η: I → M called unit | |
* |
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 scala.language.higherKinds | |
import scala.reflect.ClassTag | |
import scala.collection.{ GenMap, GenTraversable } | |
/** Draft implmementation of Polykinded Safe Type Representation & Cast */ | |
object Test extends App { | |
/** Representation of the type of a value | |
* T is the type constructor of the type of the value (For example Int => T = Int, List[Int] => T = List) | |
* TAbs (for T abstracted) is a well-formed monomorphic type derived from T (For example List => TAbs = List[Any]) |
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 scala.language.higherKinds | |
object Test extends App { | |
// PKList or the Any-Order heterogenous list | |
sealed trait PKList[Args <: AnyKind] | |
trait PKNil[Args <: AnyKind] extends PKList[Args] | |
sealed trait PKCons[Args <: AnyKind, HA, TA <: PKList[Args]] extends PKList[Args] { |
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
package papersplease2 | |
import freek._ | |
import cats.free.Free | |
import cats.{~>, Id} | |
import cats.data.Xor | |
case class Person(name: String) | |
case class Picture(person: Person) | |
case class Passedport(person: Person) |
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
/** | |
* In classic Scala implementation of hierarchies of Category theory laws (scalaz/cats), the dependency between | |
* different laws is encoded using inheritance (https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Monad.scala#L14) | |
* | |
* This approach creates well-known issues: for example, a Monad is able to _derive_ an Applicative. | |
* So sometimes, you don't have the Applicative you want but the one derived from the Monad or it doesn't | |
* compile because you have 2 Applicatives in your implicit scope. | |
* | |
* Alois Cochard has proposed a new model to represent that in (scato project)[https://github.com/aloiscochard/scato] or | |
* (scalaz/8.0.x)[https://github.com/scalaz/scalaz/blob/series/8.0.x/base/src/main/scala/typeclass/Monad.scala] branch. |
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
// Basic shapeless-style HList | |
sealed trait HList | |
sealed trait HNil extends HList { | |
def ::[H](h : H) = Test.::(h, this) | |
} | |
final case object HNil extends HNil | |
final case class ::[+H, +T <: HList](head : H, tail : T) extends HList |