Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# ((*)2) and ((<<<)1) act differently

I have these two pieces of code:

  • [| 0 .. N-1 |] |> Array.map((<<<)1)

  • [| 0 .. N-1 |] |> Array.map((*)2)

I thought they do absolutely the same things but they don't. In first case I get 1, 2, 4 and in second - 0, 2, 4. I don't understand why there is 1 in the first case? If I write let a = 0 <<< 1, I get 0. Is this a bug? Thanks!

like image 783
Savenkov Alexey Avatar asked Mar 26 '26 13:03

Savenkov Alexey


1 Answers

The arguments are not in the order you think, they are the other way around.

Compare it with:

let a = 1 <<< 0 // this is equivalent to ((<<<)1) 0

The first argument after the parenthesized operator is the left argument, not the right.

like image 79
Gus Avatar answered Mar 29 '26 03:03

Gus