↧
Answer by Zeta for How to write an expression over a data type and print it...
First of all, expr has the wrong type. expr :: Poly would be correct. You could also ask GHCi about that type:> :t Add (Lit 1) $ Add (Var) $ Mul (Var) $ Mul Var VarAdd (Lit 1) $ Add (Var) $ Mul...
View ArticleHow to write an expression over a data type and print it out in haskell?
I am having to write an expression to construct a Poly representation of the polynomial x^3 + x + 1.My algebraic data type Poly, which I wrote is:data Poly = Lit Integer | Var | Add Poly Poly | Mul...
View Article