Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / PML.org
Last active January 24, 2024 03:37
Notes on Per Martin-Löf's "On the Meanings of the Logical Constants and the Justifications of the Logical Laws"

Per Martin-Löf’s (OMLCJLL)

“On the Meanings of the Logical Constants and the Justifications of the Logical Laws”

Intro

I know I tried to write up the Meetup announcement to draw people here with a computer science or programming background. And then I threw at you this dense philosophical paper which assumes you’re familiar with names like Gentzen and languages like German and Greek not Javascript or C#.

So, that was pretty unfair of me, I apologize. In order to amend

@tel
tel / gist:7ad4dafb6c39221fc773
Last active November 13, 2023 18:31
Lennart Augustsson's "Simpler, Easier!", copied (without permission) to get around the Great Fire Wall

Simpler, Easier!

Lennart Augustsson, Oct 25, 2007

In a recent paper, Simply Easy! (An Implementation of a Dependently Typed Lambda Calculus), the authors argue that type checking a dependently typed language is easy. I agree whole-heartedly, it doesn't have to be difficult at all. But I don't think the paper presents the easiest way to do it. So here is my take on how to write a simple dependent type checker. (There's nothing new here, and the authors of the paper are undoubtedly familiar with all of it.)

I'll start by implementing the untyped lambda calculus. It's a very simple language with just three constructs: variables, applications, and lambda expressions, i.e.,

@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 / MutuallyDefined.hs
Last active April 20, 2023 06:34 — forked from gallais/MutuallDefined.hs
Mutually defined data types with recursion principle
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
@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 / indents.md
Created November 20, 2016 19:47
Indentation sensitive parser combinators

Indentation sensitive parser combinators

An indentation sensitive parser combinator language is one that helps you express ideas like "this parse only succeeds if it's within the current indentation block". The concept is somewhat small and elegant and is implemented in a few libraries. In this writeup, I will use examples from indents.

Background and goal

The direct goal will be to write the sameOrIndented parser combinator with a type

@tel
tel / ParserCombinators.hs
Created November 3, 2014 19:54
Monad transformers and parser combinators
{-# 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!
@tel
tel / Lens.scala
Created June 21, 2016 14:31
Scala profunctor lens
import scala.language.higherKinds
import scala.language.implicitConversions
trait Pt[C[_[_, _]], S, T, A, B] {
def apply[~>[_, _]](ex: C[~>])(p: A ~> B): S ~> T
}
trait Profunctor[~>[_, _]] {
def dimap[X, Y, A, B](f: X => A, g: B => Y)(p: A ~> B): X ~> Y
@tel
tel / Quantity.scala
Created November 2, 2016 21:59
Quantities and quantified sets
package jspha.comms
import scala.language.higherKinds
sealed trait Quantity {
type T[_]
}
object Singular extends Quantity { self =>
case class T[A](v: A) extends Quantity.Set[A] {
@tel
tel / Maia.scala
Last active December 13, 2020 18:57
package com.jspha.maia
import scala.language.higherKinds
import shapeless._
import shapeless.ops.hlist.Mapped
trait Maia {
trait Api {
type Fields <: HList