01/13/2012. From a lecture by Professor John Ousterhout at Stanford, class CS140
Here's today's thought for the weekend. A little bit of slope makes up for a lot of Y-intercept.
[Laughter]
data Exp r = Const r | Add (Exp r) (Exp r) | Subtract (Exp r) (Exp r) | |
eval :: (Num r) => Exp r -> r | |
eval (Const v) = v | |
eval (Add e1 e2) = (eval e1) + (eval e2) | |
eval (Subtract e1 e2) = (eval e1) - (eval e2) | |
reify :: (Show r) => Exp r -> String | |
reify (Const v) = show v | |
reify (Add e1 e2) = concat ["(",reify e1,"+",reify e2,")"] |
/* | |
ID: stphung1 | |
LANG: JAVA | |
TASK: friday | |
*/ | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Arrays; | |
import java.util.Scanner; |