Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / Huff.hs
Created December 9, 2014 05:11
Huffman
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Huff where
@tel
tel / FreeCat.hs
Created December 31, 2014 22:12
FreeCat?
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
module FreeCat where
import Control.Category
import Prelude hiding ((.), id)
data Cat p a b where
Inj :: p a b -> Cat p a b
@tel
tel / CPS.hs
Created January 1, 2015 00:53
CPS causes function composition to flip directions
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
type b <~ a = forall c . (b -> c) -> a -> c
back :: (a -> b) -> (b <~ a)
back f = (. f)
fwd :: (b <~ a) -> (a -> b)
fwd g = g id
@tel
tel / HetComp.hs
Created January 1, 2015 16:32
Really ugly Het Compose thing
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
module HetComp where
type family as ++ bs :: [k] where
@tel
tel / Tesser.hs
Created January 1, 2015 21:21
Tesseralike, but not there yet
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Data.List (foldl')
import Data.Profunctor
import Data.Bifunctor
@tel
tel / CBPV.hs
Last active August 29, 2015 14:12
PHOAS Call-by-push-value... Kind of!
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE LambdaCase #-}
-- Code obviously based on <http://andrej.com/plzoo/html/levy.html>
-- This is right now *not really* CBPV. In particular, the Rec binder
-- is both less well-behaved and far more complex than it ought to
-- be. Instead of passing a computation back (which should never be
-- possible as variables do not have computation types) it should pass
-- back a thunk.
@tel
tel / CBPV.hs
Last active August 29, 2015 14:12
Call by push value, actually
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE LambdaCase #-}
-- Code obviously based on <http://andrej.com/plzoo/html/levy.html>
module CBPV where
import Control.Applicative
import Control.Monad
@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 / 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 / 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