考虑以下代码:
type Fruit = Apple | Banana
let totalCost fruits =
fruits
|> Seq.map (fun fruit ->
match fruit with
| Apple -> 0.50
| Banana -> 0.70
)
|> Seq.sum
我可以用删除totalCost
标识符的方式重写fruit
来使其更简洁吗?
类似这样的东西:
// Not real code
let totalCost fruits =
fruits
|> Seq.map (
match
| Apple -> 0.50
| Banana -> 0.70
)
|> Seq.sum
答案 0 :(得分:7)
您要查找的关键字是function
:
|> Seq.map (
function
| Apple -> 0.50
| Banana -> 0.70
)
function
降为fun x -> match x with