Skip to content

Instantly share code, notes, and snippets.

View lukeg101's full-sized avatar

Luke Geeson lukeg101

View GitHub Profile

Keybase proof

I hereby claim:

  • I am lukeg101 on github.
  • I am lukegeeson (https://keybase.io/lukegeeson) on keybase.
  • I have a public key ASAh1wxAqrwihxrfGR0j9ob8zxqRiiO7DMyjQk5xlZB5rAo

To claim this, I am signing this object:

@lukeg101
lukeg101 / CataParser.hs
Last active April 21, 2018 21:36
Monadic Parser Combinators for Cata Language - Inductive types + STLC
module Parser where
import Cata
import Control.Applicative (Applicative(..))
import Control.Monad (liftM, ap, guard)
import Data.Char
{-
Implementation based on ideas in Monadic Parser Combinators paper
http://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf
/*
notes from http://www.warski.org/blog/2012/12/starting-with-scala-macros-a-short-tutorial/
*/
//compile this first in a separatefile
import language.experimental.macros
import reflect.macros.Context
object DebugMacros {
@lukeg101
lukeg101 / SystemF.hs
Last active March 16, 2018 22:21
Haskell Implementation of SystemF
module SystemF where
import Data.Map.Lazy as M
import Data.Set as S
import Control.Monad (guard)
import Debug.Trace
data T
= TVar Int
| TArr T T
@lukeg101
lukeg101 / SystemT.hs
Last active May 22, 2018 04:13
haskell implementation of Godel's System T (typed Lambda calculus with Nats as a base type)
module SystemT where
import Data.Map as M
import Data.Set as S
data T
= TNat
| TArr T T
deriving (Eq, Ord)
@lukeg101
lukeg101 / STLC.hs
Last active March 21, 2018 17:55
Haskell Implementation of Church style Simply Typed Lambda Calculus
module STLC where
import Data.Map as M
import Data.Set as S
-- Simple Types for Lambda Calc, of the form 'o' or 'o -> o' or a mix of both
data T
= TVar
| TArr T T
deriving (Eq, Ord) --equivalence of types compares the binary trees of each type
module ULC where
import Data.Set as S
import Data.Map.Lazy as M
--untyped lambda calculus - variables are numbers now as it's easier for renaming
data Term
= Var Int
| Abs Int Term
| App Term Term
type expr = Val of int | Add of expr * expr;;
type exprValue = int;;
type code = HALT | PUSH of exprValue * code | ADD of code;;
let rec eval x =
match x with
| Val n -> n
| Add (x, y) -> (eval x) + (eval y);;
let rec comp' x t =
import itertools
def f(input, alphabet):
list = []
for symbol in alphabet:
if symbol in input:
input = input.replace(symbol, "")
list.append(symbol)
if input == "":
return list
{-# LANGUAGE GADTs #-}
--source language
data Expr = Val Int | Add Expr Expr
--target langauge
data Code where
HALT :: Code
PUSH :: Int -> Code -> Code
ADD :: Code -> Code