- Alejando Serrano (47 Degrees)
- Searching for one ;)
const compose = (f, g) => x => f(g(x)) | |
const Id = x => | |
({ | |
fold: f => f(x), | |
map: f => Id(f(x)) | |
}) | |
Id.of = Id | |
const Tuple = (_1, _2) => |
const Prod = t => ({ | |
extract : () => t[1], | |
extend : f => Prod([t[0], f([t[0], t[1]])]), | |
map : f => Prod([t[0], f(t[1])]), | |
duplicate : () => Prod([t[0], Prod(t)]) | |
}); | |
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, Rank2Types #-} | |
import Control.Applicative | |
import Control.Monad | |
import Data.Functor.Identity | |
import Data.Foldable | |
import Data.Monoid | |
import Data.Tagged | |
class Profunctor p where | |
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d |
{-# LANGUAGE RankNTypes #-} | |
import Control.Applicative | |
import Data.Functor.Identity | |
import Data.Monoid | |
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t | |
type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t | |
_1 :: Lens (a,b) (a',b) a a' |
console.log("\033[39mRunning tests…"); | |
function assertEquals(actual, expected, description) { | |
if(typeof actual === "undefined") { | |
console.error("\033[31m" + description + " not implemented\033[39m"); | |
} else { | |
if(actual !== expected) { | |
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m"); | |
} else { | |
console.log(description + " \033[32m ok\033[39m"); | |
} |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
module ParserCombinators where | |
{- | |
We'll build a set of parser combinators from scratch demonstrating how | |
they arise as a monad transformer stack. Actually, how they arise as a | |
choice between two different monad transformer stacks! |