Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created February 8, 2013 00:05
Show Gist options
  • Save Rembane/4735419 to your computer and use it in GitHub Desktop.
Save Rembane/4735419 to your computer and use it in GitHub Desktop.
data Alg = Num' Int
| Add Alg Alg
| Sub Alg Alg
| Mul Alg Alg
deriving (Show)
consume :: Alg -> Int
consume (Num' x) = x
consume (Add a b) = (consume a) + (consume b)
consume (Sub a b) = (consume a) - (consume b)
consume (Mul a b) = (consume a) * (consume b)
-- ((7 + 5) * 3) - 10
main = putStrLn $ show $ consume (Sub (Mul (Add (Num' 7) (Num' 5)) (Num' 3)) (Num' 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment