简体   繁体   中英

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!
                          

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 = [(+), (-), (*), (/)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM