A191919
A191919

Reputation: 3442

F# This value is not a function

Playing with F# and it seems that i cannot find out what is wrong.

FS0003 This value is not a function and cannot be applied. Did you forget to terminate a declaration?

evaporator 25.0 10.0 10.0

let evaporator (volumeMl:double) (evapPerDaydouble:double) (threshold:double):int =
    let mutable counter = 0
    let mutable currentVolume = volumeMl
    while (currentVolume > (volumeMl * (threshold / 100.))) do
        currentVolume <- currentVolume - ((currentVolume * threshold / 100.))
        counter <- (counter + 1)
    counter

let result = evaporator 25.0 10.0 10.0

printfn "%f" result 

Update

modified code with ;;

let result = evaporator 25.0 10.0 10.0;;

And it is working like expected. Strange.

Update 2

enter image description here

Upvotes: 1

Views: 239

Answers (2)

Despertar
Despertar

Reputation: 22362

This can happen if there is leading whitespace. The following example produces this error.

        let x = 1
let y = 2

Removing the leading whitespace resolves the issue.

let x = 1
let y = 2

Setting your editor to show whitespace will help detect this.

The reason adding ;; also helps is because it terminates the blocked code created by the leading whitespace.

Upvotes: 0

TheQuickBrownFox
TheQuickBrownFox

Reputation: 10624

The only problem with your initial code is that you've used printfn "%f" instead of printfn "%i".

If your issue is fixed by adding ;; it makes me think you are running this in FSI and seeing the compiler error in FSI. This is fine but perhaps you are typing or pasting code directly in to the FSI prompt?

My advice to everyone starting with F#, and even experienced F# users, is to never type or paste code into FSI. Write code in your editor, select it, and send it to FSI. This way you don't need to worry about remembering semi-colons, and you get compiler errors and suggestions as you type. I have worked in F# day-to-day for years and never had the need to type directly into FSI.

Also, don't forget to re-run all your function and type definitions in FSI if you change them. It's best to reset FSI and start with clean state if you're seeing confusing errors.

Upvotes: 5

Related Questions