Haskell:使用lambda表达式的匿名函数列表

问题描述

我对Haskell还是很陌生,我想使用lambda表达式定义一个匿名函数列表, 代表四种基本的算术运算。

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!
                          

解决方法

您必须定义一个列表。

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

更简单地定义为

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