Reputation:
This compiles and works:
let rec HelloEternalWorld _ = Console.ReadLine() |> printf "Input: %s\n" HelloEternalWorld 0 HelloEternalWorld 0
This does not compile:
let rec HelloEternalWorld = Console.ReadLine() |> printf "%s\n" HelloEternalWorld HelloEternalWorld
I try to understand why not?
Upvotes: 3
Views: 685
Reputation: 49218
Please post the error messages you get, they say everything you need!
The value ... will be evaluated as part of its own definition.
Your code doesn't compile because you're declaring a recursive value (which doesn't exist) instead of a recursive function.
In order to make this a function, you'll have to write something like
let rec HelloEternalWorld() =
Console.ReadLine() |> printfn "%s"
HelloEternalWorld()
which is now a function of type unit -> unit
.
Upvotes: 4
Reputation: 6081
All you're missing are parentheses, as it would compile if it were:
let rec HelloEternalWorld() =
Console.ReadLine() |> printf "%s\n"
HelloEternalWorld()
To define a function with no arguments you need the parentheses to distinguish the function from a simple value.
Upvotes: 7