Haskell : 使用 lambda 表达式的匿名函数列表
Haskell : List of anonymous functions using lambda expressions
我是 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 = [(+), (-), (*), (/)]
我是 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 = [(+), (-), (*), (/)]