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
{- 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 |
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
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 |
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
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)) |
NewerOlder