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?
Parentheses have multiple functions relating to functions and structures. They are used to contain a list of parameters passed to functions and control structures and they are used to group expressions to control the order of execution.
Parentheses perform four basic functions in written American English: enclose numbers and letters in a list, enclose clarifications, introduce emphasizations, enclose asides and additional information.
Parentheses also signify a break in thought, but they mark an addition of information rather than an interruption like dashes do. Rather than a surprise (like dashes), parentheses are a gentler insertion in your sentence. Also like dashes, parentheses should be used sparingly.
Use parentheses to enclose information that clarifies or is used as an aside. Example: He finally answered (after taking five minutes to think) that he did not understand the question. If material in parentheses ends a sentence, the period goes after the parentheses. Example: He gave me a nice bonus ($500).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With