This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HelloWorld{ | |
def main(args: Array[String]) { | |
//this is a comment and this is hello world in scala! | |
println("Hello, world!") | |
//variable assignment | |
var meaningOfLife = 42 | |
//invoking a function we made below |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SystemT where | |
import Data.Map as M | |
import Data.Set as S | |
data T | |
= TNat | |
| TArr T T | |
deriving (Eq, Ord) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer