add impl
This commit is contained in:
parent
1c9c9422e2
commit
3aeae3617e
@ -1,5 +1,6 @@
|
|||||||
data Atree = Number Int | Variable String | Plus Atree Atree | Minus Atree | Times Atree Atree
|
data Atree = Number Int | Variable String | Plus Atree Atree | Minus Atree | Times Atree Atree
|
||||||
|
|
||||||
|
-- (5 - x) * (2y - (x + 7)))
|
||||||
t :: Atree
|
t :: Atree
|
||||||
t =
|
t =
|
||||||
Times
|
Times
|
||||||
@ -14,4 +15,8 @@ type Polynomial = [Monomial]
|
|||||||
type Monomial = (Int, [String])
|
type Monomial = (Int, [String])
|
||||||
|
|
||||||
polynomial :: Atree -> Polynomial
|
polynomial :: Atree -> Polynomial
|
||||||
polynomial = undefined
|
polynomial (Number n) = [(n, [])]
|
||||||
|
polynomial (Variable v) = [(1, [v])]
|
||||||
|
polynomial (Plus e1 e2) = polynomial e1 ++ polynomial e2
|
||||||
|
polynomial (Minus e) = map (\(c, xs) -> (-c, xs)) (polynomial e)
|
||||||
|
polynomial (Times e1 e2) = concatMap (\(c1, xs1) -> map (\(c2, xs2) -> (c1 * c2, xs1 ++ xs2)) (polynomial e2)) (polynomial e1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user