module - Why do F# functions evaluate before they are called? -
if define module such:
module module1 open system let foo = console.writeline("bar")
then, in interactive do
#load "library1.fs" //where module defined open module1
i see
[loading c:\users\jj\documents\visual studio 2015\projects\library1\library1\library1.fs] bar
indicating foo function ran without me calling it!
how/why happen? there way prevent it?
i'm aware return value of foo whatever (console.writeline("bar")) evaluates to, , there isn't reason can't evaluated "immediately?" (when module loaded guess?) - there way prevent happening? if module functions alter state of other stuff, can ensure not evaluate until called?
function bodies evaluated when function called, want. problem foo
not function, it's variable.
to make foo
function, need give parameters. since there no meaningful parameters give it, unit value (()
) conventional parameter:
let foo () = console.writeline("bar")
accordingly call of function foo ()
.
Comments
Post a Comment