Mathias
Mathias

Reputation: 15391

Usage of parenthesis in F#

I am having an issue understanding the usage of parenthesis in F#. To illustrate with a simple example, the 2 following console apps behave very differently. The first one doesn't wait for me to type in anything:

open System
let Main =
   Console.WriteLine "Hello"
   Console.ReadLine

Whereas the second one does:

open System
let Main =
   Console.WriteLine "Hello"
   Console.ReadLine()

How should I understand the difference?

Upvotes: 8

Views: 783

Answers (1)

manojlds
manojlds

Reputation: 301077

If a function takes no parameters, you specify the unit value () as the argument, as in the following line of code.

initializeApp()

The name of a function by itself is just a function value, so if you omit the parentheses that indicate the unit value, the function is merely referenced, not called.

http://msdn.microsoft.com/en-us/library/dd233229.aspx

That is why you have to do Console.ReadLine() rather than Console.ReadLine ( the latter returns a function delegate)

Upvotes: 12

Related Questions