Skip to content

Instantly share code, notes, and snippets.

View awave1's full-sized avatar

Artem Golovin awave1

  • Vancouver, Canada
  • 13:11 (UTC -07:00)
View GitHub Profile
#include <stdio.h>
/**
* Grammar for this parser
*
* S -> E
* E -> E '+' F | F
* F -> number | '(' E ')'
*
* Without immediate left recursion
-- |
-- | CPSC 521 Tutorial: 06.04.2020
-- |
data TypeExpr v = Fun (TypeExpr v) (TypeExpr v)
| Var String
-- | Prod (LType v) (LType v)
-- | List (LType v) (LType v)
-- | Nat
-- | Unit
deriving (Show, Eq)
module TutAssignment where
{-
introducing basic data types for A3
-}
-- First step: Notes have inductive definition of extended Lambda calculus
-- NOTE: Wrong, since it's typed
-- data BExp x
#!/usr/bin/env python
from collections import Counter
from itertools import cycle
import string
import re
def get_text():
with open('ulysses', 'r') as f:
state thing a
thing -> (thing, a)
b -> state thing a

Alpha Renaming w/ State Monad

@awave1
awave1 / string.l
Last active February 26, 2020 17:11
%{
#include ... // your includes
// ensure that string_builder is initialized within the scanner, otherwise reading string tokens will fail
static string_builder_t *sb = sb_init();
%}
...the rest of your lexer stuff
%%
  1. a renaming

    1. state monad
    Fun (f, _, expr)
    -- replace f with f_n where n is the variable(?)
    -- then, fun.num++;
    -- in expr, substitute all occurrences of f with f_n
fun somefun (a,b,c) =
let
fun add (x,y) = x + y
fun sub (y,z) = y - z
in
add (a,b) + sub (b,c)
module AST where
newtype Prog a b = Prog [Fun a b]
newtype Fun a b = Fun (a, [b], Exp a b)
data BoolExp a b = Lt (Exp a b) (Exp a b)
| Gt (Exp a b) (Exp a b)
| Eq (Exp a b) (Exp a b)
| AND (BoolExp a b) (BoolExp a b)
| OR (BoolExp a b) (BoolExp a b)
stack --stack-yaml=install/shake.yaml --numeric-version
git submodule sync
git submodule update --init
stack --stack-yaml=stack-8.6.5.yaml install
********************************************************************************
Building failed, Try running `stack clean` and restart the build
If this does not work, open an issue at
https://github.com/haskell/haskell-ide-engine
********************************************************************************