
Hi, How do I turn a value into an expression I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1) Any ideas J

2009/11/9 John Moore
Hi, How do I turn a value into an expression I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1)
Any ideas
J _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
import Prelude hiding ((-)) data Val a = Val a deriving Show data Expr a b = Subtract a b deriving Show (-) :: Num a => a -> a -> Expr (Val a) (Val a) x - y = Subtract (Val x) (Val y)
4 - 3 Subtract (Val 4) (Val 3)
-- Deniz Dogan

On Mon, Nov 09, 2009 at 10:05:43PM +0000, John Moore wrote:
Hi, How do I turn a value into an expression I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1)
Any ideas
Is this a homework problem? One good approach would be to make a data type Expr which represents expressions. It will have a constructor Val, a constructor Subtract, etc., one constructor for each operation you want to have in your expressions. Then make Expr an instance of the Num type class. -Brent
participants (3)
-
Brent Yorgey
-
Deniz Dogan
-
John Moore