Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of parenthesis in F#

Tags:

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?

like image 743
Mathias Avatar asked Nov 22 '11 06:11

Mathias


People also ask

What is the purpose of the parenthesis in the function?

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.

What are the 4 functions of parentheses?

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.

What effect do the parentheses () have?

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.

What are parentheses used for example?

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).


1 Answers

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)

like image 167
manojlds Avatar answered Oct 20 '22 22:10

manojlds