Skip to content

Instantly share code, notes, and snippets.

import scalaz._, Free._
sealed trait Arithmetic[+A]
sealed case class Addition[A](a: Int, b: Int, f: Int => A) extends Arithmetic[A]
object Arithmetic {
implicit val ArithmeticFunctor: Functor[Arithmetic] = new Functor[Arithmetic] {
def map[A, B](fa: Arithmetic[A])(f: A => B) = fa match {
case z@Addition(_, _, g) => z.copy(f = f compose g)
}
@luciferous
luciferous / README.md
Created September 29, 2012 13:11
Do-notation in Javascript

do.js

An experimental Javascript library that can be used for asynchronous control flow, non-determinism, parsing, and other kinds of computations which implement the interface:

bind :: m a -> (a -> m b) -> m b
return :: a -> m a

This gist is a temporary living situation for do.js, and will most likely be expanded into a full blown Github repository in the future.

@arosien
arosien / runar-io-free.scala
Last active September 10, 2016 07:17
Translation of Runar's ScalaIO 2013 presentation on IO and Free monads (http://blog.higher-order.com/assets/scalaio.pdf) to scalaz.
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {
@YoEight
YoEight / process.hs
Created February 9, 2014 18:47
Possible Process Haskell impl.
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
module Data.Process where
import Prelude hiding (zipWith)
import Control.Applicative
import Control.Monad
import Data.Foldable
@pchiusano
pchiusano / finallytagless.scala
Last active March 13, 2018 11:28
Finally tagless encoding of GADTs in Scala
trait ConsoleAlg[F[_]] {
def readLine: F[Option[String]]
def printLine(line: String): F[Unit]
}
trait Console[+A] {
def run[F[+_]](F: ConsoleAlg[F]): F[A]
}
object Console {