[Haskell-beginners] turning a value into an expression

Brent Yorgey byorgey at seas.upenn.edu
Mon Nov 9 20:21:12 EST 2009


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


More information about the Beginners mailing list