【问题标题】:Haskell : List of anonymous functions using lambda expressionsHaskell:使用 lambda 表达式的匿名函数列表
【发布时间】:2021-01-15 01:47:15
【问题描述】:

我对 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!
                          

【问题讨论】:

    标签: haskell lambda arithmetic-expressions


    【解决方案1】:

    你必须定义一个列表。

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

    更简单的定义为

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-27
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多