Konrad
Konrad

Reputation: 7247

Why can't I pipeline functions with explicit types

I'm F# beginner

Works:

let add x y = x + y
let x : decimal = 2 |> add 3

Doesn't work:

let add (x : decimal, y : decimal) = x + y
let x : decimal = 2m |> add 3m

Upvotes: 2

Views: 59

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236328

Because (x : decimal, y : decimal) is a tuple of two decimals. And signature of your function is decimal * decimal -> decimal. I.e. it accepts single parater (tuple) and returns decimal value.

You need to pass two parameters instead: (x : decimal) (y : decimal)

let add (x : decimal) (y : decimal) = x + y // decimal -> decimal -> decimal
let x = 2m |> add 3m

Remember, if you see , in F# then you are looking at tuple. Comma is not used as a parameter delimiter here.

Upvotes: 7

Related Questions