Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / deku.d.ts
Last active August 29, 2015 14:21
Deku typescript definitions file
// CORE API
// --------------------------------------------------------------------
/**
* Take an Application and paint it into the DOM at a given root node.
*/
declare function render(tree: Application, root: Node): void;
/**
@tel
tel / maybe.ts
Created May 11, 2015 22:31
Maybe for TypeScript
'use strict';
export interface Tuple<A, B> {
fst: A;
snd: B;
}
export module Tuple {
export function of<A, B>(a: A, b: B): Tuple<A, B> {
return {fst: a, snd: b};
@tel
tel / NonHask.hs
Created April 20, 2015 20:02
A rather non-traditional, non-Hask functor in Haskell
{-# LANGUAGE DataKinds
, TypeFamilies
, TypeOperators
, GADTs
, KindSignatures #-}
data Nat = Z | S Nat
type family Plus n m :: Nat where
Plus Z m = m
@tel
tel / Tracker.ml
Last active August 29, 2015 14:18
Meteor Tracker Goji binding
open Goji
let tracker_package =
register_package
~version:"1.0.7"
~doc:"Simple, push-based reactivity."
"tracker"
let tracker_component =
register_component
@tel
tel / vdom.ml
Last active August 29, 2015 14:17
Vdom in OCaml
module StringLike = struct
type t = string
let of_string : string -> t = fun s -> String.lowercase s
let to_string : t -> string = fun s -> s
let compare : t -> t -> int = String.compare
end
module Tag = struct
@tel
tel / Parser.ml
Created March 21, 2015 20:26
OCaml binary parser monad
module Opt = struct
module Core = struct
type 'a t = 'a option
let pure a = Some a
let map f = function
| None -> None
| Some a -> Some (f a)
@tel
tel / vlcps.ml
Last active February 19, 2023 01:40
OCaml van Laarhoven CPS lenses.
module Sum = struct
type (+'a, +'b) sum = Inl of 'a | Inr of 'b
type (+'a, +'b) t = ('a, 'b) sum
let bimap f g = function
| Inl a -> Inl (f a)
| Inr b -> Inr (g b)
let lmap f = bimap f (fun x -> x)
let rmap f = bimap (fun x -> x) f
@tel
tel / Pp.hs
Created March 21, 2015 16:17
Pure profunctor lenses
{-# LANGUAGE RankNTypes, LiberalTypeSynonyms, DeriveFunctor, LambdaCase #-}
module Pp where
import Data.Monoid
class Profunctor p where
dimap :: (a -> b) -> (s -> t) -> p b s -> p a t
class Profunctor p => Strong p where
@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 / recur.ml
Last active March 25, 2017 19:47
Not as bad as I feared
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> ('a t -> 'b t)
end
module Mu (F : Functor) : sig
type t = { mu : t F.t }
val cata : ('a F.t -> 'a) -> (t -> 'a)
end = struct