Using brackets in F #

I am having a problem understanding the use of brackets in F #. To illustrate with a simple example, the following two console applications behave differently. The first did not wait when I type something:

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

While the second one does:

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

How should I understand the difference?

+6
source share
1 answer

If the function does not accept any parameters, you specify the value of unit () as an argument, as in the next line of code.

 initializeApp() 

The name of the function in itself is only the value of the function, so if you omit the parentheses indicating the value of one, the function is simply referenced, not called.

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

This is why you need to do Console.ReadLine() , not Console.ReadLine (the latter returns a delegate to the function)

+10
source

Source: https://habr.com/ru/post/902080/


All Articles