f# - 此表达式的类型应该为 'unit',但类型为 'ConsoleKeyInfo'

标签 f# functional-programming unit-type

我只是想在F#控制台应用程序中暂停,所以我写道:

Console.ReadKey()

但这给出了警告:This expression should have type 'unit', but has type 'ConsoleKeyInfo'.
我该怎么做才能解决此问题?

最佳答案

解:

Console.ReadKey() |> ignore

说明:Console.ReadKey()返回“ConsoleKeyInfo”类型的对象,但是您将其用作语句,而没有将返回值分配给任何对象。因此,F#警告您忽略了一个值。 ignore采用任何类型,不返回任何内容。可以这样定义:
let ignore _ = ()

关于f# - 此表达式的类型应该为 'unit',但类型为 'ConsoleKeyInfo',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/324947/

相关文章:

list - F# 类型 obj 但我想要 'a

c# - 为什么 Task<T> monad 中不包含 CancellationToken?

ruby - open 关键字是 trait/mixin 吗?

F# 此表达式的类型应为 'unit' ,但类型为 'bool'

F#接口(interface)继承失败,由于单元

arrays - F#匹配数组的开头

f# - 是否有可通过 FSharp.Core 4.3.0.0 重新分发的打包运行时?

dictionary - 将 "not"添加到 Clojure 序列中的每个项目

javascript - 我们可以实现尾递归模 cons 等吗?通过蹦床?