Skip to content

Instantly share code, notes, and snippets.

View ayberkt's full-sized avatar

Ayberk Tosun ayberkt

View GitHub Profile
@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 / 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 / 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))