martavoi
martavoi

Reputation: 7092

Pipeline pow operator issue with

i want to write the next function using pipeline:

A = 1/Sum[1-k](x^2)

so when i write:

//Adaptive step
let a_Adaptive x =
    x
    |> Array.map (fun x -> x ** 2.0)
    |> Array.sum
    |> (**) -1.0

f# interpretes (**) as a multiline comment, but i want use it as a function. Any suggestions?

Upvotes: 6

Views: 114

Answers (1)

Lee
Lee

Reputation: 144166

You just need to add a space before the **:

let a_Adaptive x =
    x
    |> Array.map (fun x -> x ** 2.0)
    |> Array.sum
    |> ( ** ) -1.0

From the F# specification:

To define other operators that begin with *, whitespace must follow the opening parenthesis; otherwise (* is interpreted as the start of a comment:

let ( *+* ) x y = (x + y)

Upvotes: 7

Related Questions