Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / Tesser.hs
Last active July 8, 2020 07:18
Not yet Tesser, but getting there
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Data.List (foldl')
import Data.Profunctor
import Data.Bifunctor
@tel
tel / FAlg.ml
Created February 16, 2015 19:29
More F-algebra things in OCaml
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> ('a t -> 'b t)
end
module Iso = struct
type ('a, 'b) t = { fwd : 'a -> 'b; bck : 'b -> 'a }
let fwd i = i.fwd
let bck i = i.bck
@tel
tel / Profunctor.js
Last active April 3, 2019 01:51
"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.
*/
@tel
tel / Cont.js
Created June 4, 2015 04:24
Continuation monad in Javascript
function Cont(contHandler) {
this.contHandler = contHandler;
};
Cont.unit = function(value) {
return new Cont(function (continue) { return continue(value); });
};
Cont.prototype.run = function(resume) {
return this.contHandler(resume);
@tel
tel / Lens.js
Created June 20, 2015 05:06
Really simple van Laarhoven lenses in Javascript
const IdModule = {
fmap: (fn) => (x) => fn(x),
}
const ConstModule = {
fmap: (fn) => (x) => x,
}
/**
@tel
tel / PipeLog.hs
Last active January 13, 2018 10:03
Pipes-based logger
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module PipeLog where
import Control.Applicative
import Data.Functor.Identity
import Pipes
import qualified Pipes.Prelude as P
newtype LogT l m a =
@tel
tel / Lenses.scala
Created April 18, 2017 04:38
Pure profunctor lenses in Scala
import scala.language.higherKinds
object Lenses {
trait Profunctor[P[_, _]] {
def dimap[A, B, C, D](f: C => A, g: B => D)(p: P[A, B]): P[C, D]
}
object Profunctor {
module Rel
DecProofType : {a:Type} -> Dec a -> Type
DecProofType {a} (Yes _) = a
DecProofType {a} (No _) = a -> _|_
decProof : {a:Type} -> (dec : Dec a) -> DecProofType dec
decProof (Yes x) = x
decProof (No x) = x
@tel
tel / AssocIn.hs
Last active October 17, 2017 03:29
{-# LANGUAGE GADTs #-}
module Lib where
import qualified Data.HashMap.Lazy as M
import Data.Hashable
import Data.Typeable
-- this is what we know about all things from Java
data Val where
@tel
tel / Yana.hs
Last active March 30, 2017 05:46
-- Example code
example :: (Context m, MonadLog m, AreaDao m) => [Actor] -> m ()
example list =
forM list $ \actor -> do
logInfo $ "Actor being read: " ++ actorCode actor
areaList <- getArea actor
case areaList of
[] -> return () -- do nothing
(area : _) -> do