Why does printfn print immediately in f #?

When I run the next bit of code, I get 5050 from mySum. I defined mySum but never called it. How can he print at all? Perhaps this is strange because my background is Haskell, and I'm used to passing the IO monad to get things to do things - how / when are things evaluated in F #?

type main = obj [] -> int

let mySum =  [1..100] |> List.sum |> printfn "%i"


[<EntryPoint>]
let main argv = 
    0
+4
source share
1 answer

I defined mySum but never called it.

mySumis not a function, since it does not accept any parameters. A function must have at least one argument; if nothing can be used "useful", usually this value unit ().

mySum - ; , [1..100] |> List.sum |> printfn "%i" mySum. , , (), printfn unit. , , , , .

, mySum :

let mySum () =  [1..100] |> List.sum |> printfn "%i"

mySum ()

, 5050 , () .

+13

All Articles