haskell - Error: "No instances for (x)..." -


The exercise 14.16-17 in Thompson tells me to add type XP to the multiplication and division (integer), which shows a simple language for arithmetic, then show and eval for xp (evaluates type Expr).

My solution works for each arithmetic operation in addition to the partition:

  Data Expr = L Int | XPR: + Exp | Xp: - Xp. | Expr: * Expr | XP: EXP Instance Num Exp (L x) + (LY) = L (X + Y) (L x) - (LY) = L (X-Y) (L x) * (LY) = L ( X * y) Example eq expression where (l x) == (l y) = x == y show example expression where show (ln) = show n show (e1: + e2) = "(" ++ "Show (E1 + + + Show E2 + +)" Show (E1: - E2) = "(" ++ Show E1 ++ "-" ++ Show E2 + + ")" Show (E1: * Show) E2) = "(" ++ Show E1 ++ "*" ++ Show E2 ++ ")" Show (E1: / E2) = "( "++ Show E1 ++" / "++ Show E2 ++") "Eval :: Expr -> XMR (LN) = LN eval ( 1: + E2) = eval e1 + eval e2 eval (e1: - e2) = eval e1 - eval e2 eval (e1: * e2) = eval e1 * eval e2  

example ,

  * Main & gt; (L6: + L7): - L4 ((6 + 7) - 4) * Maine & gt; It: * L9 ((( 6 + 7) - 4) * 9) * main> it eval 81 it :: expr  

However, when I try to apply the partition when I'm running into problems I do not get the error message if I try to compile the following:

  Example integral XPR (LX) `div` (LY) = L (x` div`) Y Eval (e1: / e2) = eval e1 `div` eval e2  

this Ruti is:

  Chapter 14.15-27.hs: 1 9: 9: 14.15 to 27 chapters. In HS: 19: 9-21, an example announcement for any possible example (Ennum XP, Real XPR) arising from superclasses of announcement announcement (NUn XPR, Real XPR), for example an example announcement of `Integral In the first place for XPR ' 

, I do not know that I need to define an example to define div for the data type Enum Expr or RealEx P .

Well, this is the same way that the class integral is defined For information, you type GHCi in .

You will get class

  (Actual A, Enum A) = & Gt; Where an integral one ...  

means that a should be either integral actual and Enum before. Searest La Via


Note that you may have lost your type of information quite a bit. (LY) = L (X + Y) (L x) - (LY) = L (X - Y)

  Take a look at the example Num XPR. (L x) * (LY) = L (X * Y)  

If they wrap the plain numbers, then Expr . I'm pretty sure that you do not want to do this. You want to add arbitrary expressions and you have a syntax for it. This is just

  example Num Expr where (+) = (: +) (-) = (:-) - ...  

this allows You have to type (L1) + (L2) with a completely normal syntax. Similarly, eval should not reduce the expression but rather generate a number, and therefore the type of eval :: Expr -> Integer . The division is simple for that matter

  eval (a: / b) = (eval a) `div` (eval b)  

that you Only split the number .


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -