Skip to content

Instantly share code, notes, and snippets.

View chrilves's full-sized avatar

Christophe Calvès chrilves

View GitHub Profile
/*
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)
/*
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
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 November 23, 2018 16:31
A proof that the type `A` is of the form `F[elem]` for some type `elem`
/** 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]
import scala.collection.immutable.TreeSet
import scala.language.higherKinds
/*****************************************
* A Category
*/
trait Cat { cat =>
type obj[A]
type arr[A, B]
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]
(** 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
*)
Informations de l'ordinateur :
Fabricant : Unknown
Modèle : Unknown
Type : Ordinateur de bureau
Aucun écran tactile détecté
Processeur :
Fabricant du CPU : GenuineIntel
Marque du processeur : Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz
Famille du processeur : 0x6
import scala.language.higherKinds
object Toto {
trait Monad[M[_]] {
def pure[A](value: A): M[A]
def flatMap[A,B](ma: M[A], f: A => M[B]): M[B]
final def map[A,B](ma: M[A], f: A => B): M[B] =
flatMap(ma, f `andThen` pure)
import scala.language.implicitConversions
object CHK {
/* Quand on sait convertir un type
A dans B et réciproquement
*/
trait Conversion[A,B] { self =>
def to: A => B
def from: B => A