Skip to content

Instantly share code, notes, and snippets.

Christophe Calvès chrilves

Block or report user

Report or block chrilves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Wild_exposed_as_a_GADT.scala
/* Modified version of https://gist.github.com/non/51b83d0abc929cc4f0b153accf2bf02f
* to expose it's GADT's nature and provide the folding function.
*
* Should run out of the box with: amm <the_file>
*/
import $ivy.`org.typelevel:cats-core_2.12:1.6.0`
object demo {
import cats.{Applicative, Functor, Id, Semigroupal, Traverse}
View Lens_and_zipper_equivalence.scala
object LensToZiper {
/*
This is a small sleight of hand to show how
[lenses](https://en.wikibooks.org/wiki/Haskell/Lenses_and_functional_references)
are actually related to to zippers (getters + setters).
This connection give some insight about why lenses
have the properties they have. So let's define all
we need for lenses:
View ForceCovariance.scala
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
}
/* Any functor is by definition covariant because:
Let A and B be two types such that A <: B, then
(fa: F[A]).map((a:A) => (a:S)) : F[S]
but also
View The_Batch_Monad.scala
/*
This code was made to investigate if it is possible
to use a batch API as if it were a single item one.
More precisely, I have this batch API:
final case class Request(id: Int)
final case class Response(id: Int)
View One_concept_to_explain_them_all_and_in_the_theory_bind_them.scala
/*
This piece of commented code aims to clarify some
misconceptions between several advanced concepts
in pure functional programming/category theory:
free monads, finally tagless approach, algebraic
effects.
These concepts are actually very close. They rely
on similar concepts and even represent the "same"
object (up to isomorphism!) from the theoretical
View GADTs_For_Implicits_Demo.scala
object Test {
/** Simple definition of Heterogeneous Lists
*/
sealed abstract class HList {
def :::[H](head: H): H ::: this.type = Test.:::(head, this)
}
/** The empty list
@chrilves
chrilves / IsA.scala
Created Nov 23, 2018
A proof that the type `A` is of the form `F[elem]` for some type `elem`
View IsA.scala
/** A proof that the type {{{A}}} is of
* the form {{{F[elem]}}} for some type
* {{{elem}}}.
*/
sealed abstract class IsA[F[_], A] {
type elem
def fold[G[_]](p: G[F[elem]]): G[A]
@inline implicit final def to: A =:= F[elem] = {
type G[X] = X =:= F[elem]
View General_Category.scala
import scala.collection.immutable.TreeSet
import scala.language.higherKinds
/*****************************************
* A Category
*/
trait Cat { cat =>
type obj[A]
type arr[A, B]
View DBMode_PathDependentTypes.scala
import scala.language.higherKinds
import scala.language.implicitConversions
import scala.util.Random
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
/** A simple trait telling how to save in DB */
sealed trait DBMode {
type Op[_]
def saveInDB[A](a: A): Op[A]
View Reader_Equivalence.v
(** We aim to show that the classic Reader monad is equivalent
to an ADT (more precisely a GADT (Generalized Algebraic Data Types).
*)
Section ForStephane.
(** The reader config type (what's read)
*
* trait Config
*)
You can’t perform that action at this time.