views:

781

answers:

1

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

+15  A: 

Solution:

Console.ReadKey() |> ignore

Explanation: 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 _ = ()
namin