簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM