gpt4 book ai didi

f# - 如何从 f# 中的表达式返回单位

转载 作者:行者123 更新时间:2023-12-04 04:50:04 25 4
gpt4 key购买 nike

我如何退货 unit来自 f# 中的表达式?例如:

let readInt =
let str = Console.ReadLine()
let (succ, num) = Int32.TryParse(str)
match succ with
| true -> Some(num)
| _ -> None

match readInt with
| Some(v) -> Console.WriteLine(v)
| None -> ignore //i don't want to do anything,
// but i don't know how to ignore this brunch of the expression

最佳答案

F# 中(唯一可能的)单位值写为

()

所以你的代码变成
...
| None -> ()

关于f# - 如何从 f# 中的表达式返回单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18095978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com