Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
Bug hunting 🎯

Simon Richardson SimonRichardson

👻
Bug hunting 🎯
View GitHub Profile
@tel
tel / ProfunctorLens.js
Last active October 23, 2023 20:32
Pure Profunctor Lenses in Javascript (redux)
/* 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)
@tel
tel / Profunctor.js
Last active January 6, 2025 09:37
"Pure-profunctor" lenses in Javascript (!)
/// 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.
*/
@gbaz
gbaz / Generic.purs
Last active February 6, 2016 06:06
Generics in purescript (updated to version 7)
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
@DrBoolean
DrBoolean / Coyoneda.js
Created March 4, 2015 02:33
Coyoneda
// 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)
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@jpallari
jpallari / freefrp.js
Last active May 7, 2020 07:27
Free monad based thread simulation and FRP constructs written in JavaScript. http://stuff.lepovirta.org/r/freefrp/
// 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.
@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
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]