This blog post series has moved here.
You might also be interested in the 2016 version.
/* eslint-disable new-cap */ | |
/** | |
* Lens types. | |
* =========== | |
* | |
* a * b = {fst: a, snd: b} | |
* a + b = {index: Boolean, value: a | b} | |
* | |
* Iso s t a b = forall (~>) . Profunctor (~>) => (a ~> b) -> (s ~> t) |
/// PRELIMINARIES | |
/** | |
* Generalized "products" of any size. For gluing things together. A tuple is a | |
* "2"-meet. | |
* | |
* The type `Meet a b c d ...` indicates a `Meet` of the given size with values | |
* at each type in the sequence. | |
*/ |
module Generic where | |
import Prelude | |
import Data.Maybe | |
import Data.Traversable | |
import Data.Array | |
data GenericSpine = SProd String (Array (Unit -> GenericSpine)) | |
| SRecord (Array {recLabel :: String, recValue :: Unit -> GenericSpine}) | |
| SNumber Number |
module Main where | |
import qualified Prelude as P | |
import Debug.Trace | |
class Arithmetic lang where | |
(+) :: lang Number -> lang Number -> lang Number | |
(-) :: lang Number -> lang Number -> lang Number | |
(*) :: lang Number -> lang Number -> lang Number | |
(/) :: lang Number -> lang Number -> lang Number |
// helpers | |
var compose = function(f,g) { | |
return function(x) { | |
return f(g(x)) | |
} | |
} | |
var id = function(x) { return x } | |
require ('./globals')(global); // Mixed in Ramda to global here | |
var Task = require ('data.future'), | |
M = require ('control.monads'), | |
State = require ('fantasy-states'), | |
Reader = require ('fantasy-readers'), | |
Tuple2 = require ('fantasy-tuples').Tuple2, | |
Maybe = require ('data.maybe'), | |
ST = State.StateT (Task), | |
App = Reader.ReaderT (ST); |
/** | |
* Free applicative functors | |
*/ | |
sealed trait FreeA[F[_],A] { | |
/** | |
* The canonical monoidal natural transformation that interprets | |
* this free program by giving it the semantics of the applicative functor `G`. | |
*/ | |
def foldMap[G[_]:Applicative](f: F ~> G): G[A] = this match { | |
case Pure(x) => Applicative[G].pure(x) |
This blog post series has moved here.
You might also be interested in the 2016 version.
// Free monad based thread simulation and FRP constructs written in JavaScript | |
// First, we need some way to express lazy values and actions. | |
// We can use zero-argument functions for this purpose: call the function and | |
// you get the value. We also need to compose lazy values/actions. For that | |
// we have bindLazy function. Lazy values are not expected to be pure | |
// in this program: evaluating a lazy value/action at different times can produce | |
// a different value. |
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |