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
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE TypeInType #-} | |
module LevNum where | |
import GHC.Prim | |
import GHC.Exts (TYPE) | |
class LevNum (a :: TYPE r) where | |
levAdd :: a -> a -> a |
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
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE ExplicitForAll #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeSynonymInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
module Playground where |
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.io.StdIn._ | |
object CustomIO extends App { | |
/** | |
* Slides: https://docs.google.com/presentation/d/15O8fzIEa85a8S_vk6N3b_S8F4IYbrFkLOXmtwbcy0cQ | |
*/ | |
case class IO[A](unsafeRun: () => A) { | |
def map[B](f: A => B): IO[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
import io.circe.syntax._ | |
// hypothesis: ∀ x∈X, x.asJson.as[X] == Right(x) | |
// counterexample, nested options: | |
type X = Option[Option[Int]] | |
val x: X = Some(None) | |
x.asJson.as[X] == Right(x) |
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 shapeless.ops.record.Keys | |
import shapeless.ops.hlist.Selector | |
import shapeless.tag._ | |
/** | |
* Gets the name of a case class's field, in a type-safe way. | |
* If the class does not have a field with the given name, the program won't compile. | |
* | |
* Kinda similar to C#'s `nameof` operator, but not bolted onto the language |
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
// Exercises: https://gist.github.com/hugoferreira/21f1f0ec23186adb5e6832e6aee618d6 | |
const eq = require('lodash').isEqual | |
const fold = (as, base) => (f) => { | |
let result = base | |
for (let i = 0; i < as.length; i++) | |
result = f(result, as[i]) | |
return result | |
} |
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._, record._ | |
import io.circe._ | |
import io.circe.syntax._ | |
import io.circe.generic.encoding._ | |
case class Person(name: String, age: Int) | |
object Person { | |
implicit val encodePerson: Encoder[Person] = | |
ReprObjectEncoder.deriveReprObjectEncoder.contramap { 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
import monix.execution.Scheduler.Implicits.global | |
import monix.eval._ | |
import io.circe._ | |
import io.circe.generic.semiauto._ | |
import de.heikoseeberger.akkahttpcirce.ErrorAccumulatingCirceSupport._ | |
/** | |
POST localhost:9999/mock | |
{ |
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
/* | |
* useful links | |
* | |
* https://github.com/rickynils/scalacheck/blob/master/doc/UserGuide.md | |
* http://www.scalatest.org/user_guide/generator_driven_property_checks | |
* | |
*/ | |
import org.scalacheck._ | |
import org.scalacheck.Arbitrary._ |
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
-- start with | |
(+) >>= id $ 2 | |
-- Expand `>>=` using the Monad instance for functions | |
-- instance Monad ((->) r) where | |
-- f >>= k = \ r -> k (f r) r | |
(\r -> id ((+) r) r) $ 2 | |
-- beta reduction | |
id ((+) 2) 2 |