Why it does not compile in F #

This compiles and works:

let rec HelloEternalWorld _ = 
  Console.ReadLine () |> printf "Input:% s \ n"
  HelloEternalWorld 0

HelloEternalWorld 0

This will not compile:

let rec HelloEternalWorld = 
  Console.ReadLine () |> printf "% s \ n"
  HelloEternalWorld

HelloEternalWorld

I'm trying to understand why not?

+3
source share
2 answers

All you are missing are parentheses that would be compiled if it were:


let rec HelloEternalWorld() = 
  Console.ReadLine() |> printf "%s\n"
  HelloEternalWorld()


To define a function without arguments, you need parentheses to distinguish a function from a simple value.

+7
source

, , , , !

... .

, ( ).

, -

let rec HelloEternalWorld() = 
  Console.ReadLine() |> printfn "%s"
  HelloEternalWorld()

unit -> unit.

+4

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


All Articles