这是一个简单的问题,但由于F#非常新,我无法追踪答案。我只是想在一个F#控制台应用程序中暂停,所以我写道:
Console.ReadKey()
但是这给出了警告:这个表达式应该有'unit'类型,但是类型是'ConsoleKeyInfo'。任何帮助将不胜感激。
谢谢, - Lee
解决方案解决方案: Console.ReadKey()|>忽略解释: Console.ReadKey()返回类型为'ConsoleKeyInfo'的对象,但是您将其用作语句而不将返回值分配给任何内容。所以F#警告你,你忽略了一个值。 忽略取任何类型并且不返回任何内容。它可以这样定义: $ p $ let ignore _ =()
This is a simple question, but I'm having trouble tracking down an answer since F# is so new. I just wanted to pause in an F# console application, so I wrote:
Console.ReadKey()
But this gives the warning: This expression should have type 'unit', but has type 'ConsoleKeyInfo'. Any help would be greatly appreciated.
Thanks, - Lee
解决方案Solution:
Console.ReadKey() |> ignoreExplanation: Console.ReadKey() returns an object of type 'ConsoleKeyInfo' but you're using it as a statement without assigning the return value to anything. So F# warns you that you're ignoring a value. ignore takes any type and returns nothing. It could be defined like this:
let ignore _ = ()
更多推荐
F#:这个表达式应该有'unit'类型,但是类型'ConsoleKeyInfo'
发布评论