Move Num instance around a little.
This commit is contained in:
parent
02387bbf85
commit
3f673113b7
|
@ -16,11 +16,6 @@ data Expr
|
|||
| Mul Expr Expr -- ^ Multiplication expressions
|
||||
deriving (Eq,Show)
|
||||
|
||||
instance Num Expr where
|
||||
(+) = Add
|
||||
(*) = Mul
|
||||
fromInteger = Lit . fromInteger
|
||||
|
||||
fold :: (Int -> a) -> (a -> a -> a) -> (a -> a -> a) -> Expr -> a
|
||||
fold f1 f2 f3 = rec
|
||||
where
|
||||
|
@ -28,6 +23,11 @@ fold f1 f2 f3 = rec
|
|||
rec (Add l r) = f2 (rec l) (rec r)
|
||||
rec (Mul l r) = f3 (rec l) (rec r)
|
||||
|
||||
instance Num Expr where
|
||||
(+) = Add
|
||||
(*) = Mul
|
||||
fromInteger = Lit . fromInteger
|
||||
|
||||
-- | The expression: 2 + 3 * 4
|
||||
e1 :: Expr
|
||||
e1 = Add (Lit 2) (Mul (Lit 3) (Lit 4))
|
||||
|
|
Loading…
Reference in New Issue
Block a user