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:
I hereby claim:
To claim this, I am signing this object:
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 { |
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 |
module SystemT where | |
import Data.Map as M | |
import Data.Set as S | |
data T | |
= TNat | |
| TArr T T | |
deriving (Eq, Ord) |
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 |