Search code examples
haskelllambdaarithmetic-expressions

Haskell : List of anonymous functions using lambda expressions


i am quite new to Haskell and i want to define a list of anonymous functions using lambda expressions, which represent the four basic arithmetic operations.

this is what i have done bao = (\ x y -> x+y)
 but i want to apply 3 more expressions(\x y ->x-y)
                                       (\x y ->x*y)
                                       (\x y ->x/y) 
as well by putting bao before them just like what i have done to operation (+) ,and it shows error : multi declaration of 'bao' ,what  can i do ?

Thank you in advance!
                          

Solution

  • You have to define a list.

    bao = [\x y -> x + y, \x y -> x - y , \x y -> x * y, \x y -> x / y]
    

    which would be more simply defined as

    bao = [(+), (-), (*), (/)]