TODO: introduction
Note: the examples below use the following algebraic data type:
sealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(height: Double, width: Double) extends Shape| @gfixler, free monoid is the easiest and helps generalize the whole "free" thing | |
| let's make a monoid that is a monoid for *anything* | |
| but wait, that doesn't sound possible, everything that can be a monoid has its own rule, that's the whole point | |
| but if you wanted to make a monoid for anything, you can just be really lazy, and instead of actually adding things together, you just collect all the things you want to add | |
| "you want to add an A and an A, sure, the answer is: here's your two A's" HA HA HA free monoids rule |
| /* | |
| * Algebraic Data Types | |
| */ | |
| // A has a B and C | |
| case class A(b: B, c: C) | |
| // A is a B or C | |
| sealed trait A | |
| case class B() extends A |
| import $ivy.`org.typelevel::cats-core:1.4.0` | |
| import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| // compose "regular" functions: | |
| def a(s: String): Int = s.length | |
| def b(i: Int): Int = i + 1 | |
| def c(i: Int): String = i.toString + "!" |
Adam Rosien @arosien Inner Product LLC
Can you read this? How about you over there? :thumbs_up:
What is type-level programming?
| import cats._ | |
| import cats.data._ | |
| import cats.implicits._ | |
| object KleisliReader { | |
| val k = Kleisli[Id, Int, String](i => (i + 1).toString) | |
| Contravariant[Reader[?, String]] // not found | |
| Contravariant[Kleisli[Id, ?, String]] // not found |
| import cats._ | |
| import cats.implicits._ | |
| /* | |
| Box a: forall b. (a -> b) -> b | |
| Codensity f a: forall b. (a -> f b) -> f b | |
| Yoneda f a: forall b. (a -> b) -> f b | |
| https://stackoverflow.com/questions/45287954/is-having-a-a-b-b-equivalent-to-having-an-a | |
| */ |
| @startuml | |
| concise "Client" as Client | |
| concise "Server" as Server | |
| concise "Response freshness" as Cache | |
| Server is idle | |
| Client is idle | |
| @Client | |
| 0 is send |
| case class RoseF[V, A](root: V, children: List[A]) | |
| object RoseF { | |
| type Fixed[V] = Fix[RoseF[V, ?]] | |
| implicit def traverse[V]: Traverse[RoseF[V, ?]] = | |
| new DefaultTraverse[RoseF[V, ?]] { | |
| def traverse[G[_]: Applicative, A, B]( | |
| fa: RoseF[V, A] | |
| )(f: A => G[B]): G[RoseF[V, B]] = |
Functional programming is full of Fancy Words™. Let's collect a list of them to demystify together. Adam will facilitate with live-coding, and will also try to make good jokes.
Here's some terms to bootstrap us: effect, free monad, functor, property-based testing, refinement type, stream, etc. >