Skip to content

Instantly share code, notes, and snippets.

View ayberkt's full-sized avatar

Ayberk Tosun ayberkt

View GitHub Profile
@ayberkt
ayberkt / currying.py
Last active August 29, 2015 14:24
Sample curried function
def curried_f(x, y=None, z=None):
def f(x, y, z): return x**3 + y**2 + z
if y is not None and z is not None:
return f(x, y, z)
if y is not None:
return lambda z: f(x, y, z)
return lambda y, z=None: f(x, y, z) if (y is not None and z is not None) else (lambda z: f(x, y, z))
@ayberkt
ayberkt / trees.hs
Last active November 1, 2015 21:35
data Tree a = EmptyTree
| Node a (Tree a) (Tree a)
deriving (Eq, Ord, Show)
simpleTree :: Tree Int
simpleTree = Node 1 (Node 2 EmptyTree EmptyTree)
(Node 3 EmptyTree EmptyTree)
tree1 :: Tree Int
@ayberkt
ayberkt / arithmetic.hs
Last active November 17, 2015 21:54
Tiny polish notation arithmetic interpreter in Haskell.
{- Based on Miran Lipovaca's RPN solver from LYAH. -}
import Control.Monad (forever)
apply :: String -> [Double] -> [Double]
apply "*" (x:y:ys) = (x * y):ys
apply "+" (x:y:ys) = (x + y):ys
apply "-" (x:y:ys) = (x - y):ys
apply "/" (x:y:ys) = (x / y):ys
apply "exp" (x:y:ys) = (x ** y):ys
@ayberkt
ayberkt / Makefile
Last active December 7, 2015 20:42
Makefile for LaTeX
all:
pdflatex paper.tex
bib:
latex paper.tex && bibtex paper.aux && latex paper.tex && pdflatex paper.tex
clean:
rm -f paper.pdf
rm -f paper.aux
rm -f paper.log
(define-fun is-prob ((r Real)) Bool (and (>= r 0) (<= r 1)))
(define-fun equi ((a Real) (b Real) (c Real) (d Real) (r Real) (s Real)) Real
(+ (* r s a) (* r (- 1 s) b) (* (- 1 r) s c) (* (- 1 r) (- 1 s) d)))
(assert
(forall ((x1 Real) (y1 Real) (w1 Real) (z1 Real)
(x2 Real) (y2 Real) (w2 Real) (z2 Real))
(exists ((r Real) (s Real))
(=>
@ayberkt
ayberkt / regexp.sml
Created July 21, 2017 23:35
Code from Harper's Proof-Directed Debugging
structure Regex =
struct
datatype regexp =
Zero
| One
| Char of char
| Times of regexp * regexp
| Plus of regexp * regexp
| Star of regexp
@ayberkt
ayberkt / CityTur.gf
Last active August 15, 2017 08:44
CityTur.gf
concrete CityTur of City = open Prelude in {
flags
lexer=bind;
param
WowelType = Front | Back;
DefAccCase = OnlyI WowelType | SoftenCons WowelType | InsertY WowelType;
lincat
Phrase = Str;
@ayberkt
ayberkt / gf-resources.md
Created August 28, 2017 18:48
GF Documentation Pointers
@ayberkt
ayberkt / id_rsa.pub
Created October 4, 2017 16:29
Public RSA key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDB/ThJZfpaHI337U5cq56ydyg8PuoYUYfxgRkbHTIq24JLO49x6YxsyaFL2cqHZwmzLMuMQrGtOlznnc+Ud88ni6nfgHX1zztNNFZ6EzUXsEKIXqqmuQEGXWg1pLuMMRjB6qaG781K3Lrd3yjmXA8+f5/+3aLAv85cy+tVeZsF8dyAhyBq75wLj1E2kNfBcqBbZkGek4UgzSL/9MqgtTQp9vWAPpR+d8RznIf79iZo0sPmNyW0nOzPFJiMbOcbN8fEChPQv3xGM7AWzdCxY+hGlnqk/Ki3b4+7rmZ5a+j+NqLogmMABeSwwdmDzWRvUKt/yzsZ9KNAfJqZTCTfChNd tosun2@illinois.edu