-- countdown.hs
data Op   = Add | Sub | Mul | Div      deriving (Show)
data Expr = Val Int | App Op Expr Expr deriving (Show)

apply         :: Op -> Int -> Int -> Int
apply Add x y =  x+y
apply Sub x y =  x-y
apply Mul x y =  x*y
apply Div x y =  x `div` y

solutions      :: [Int] -> Int -> [Expr]
solutions ns n =  [ e | ns' <- subbags ns, e <- exprs ns', 
                        eval e == [n]]

