Hello!

Please help me with the work of the return conveyors.

Suppose there is a piece of code:

let add xy = x + y [<EntryPoint>] let main argv = add 2 <| add 3 <| 4 |> add 7 |> add 8 

This code is incorrect, but it will be correct if you remove add 2 <|

Why is this code incorrect now? What is passed to add 2 ?

  • And you try to figure out a simpler example - user227049
  • @FoggyFinder Well, I understand what is happening here: add 2 <| 2 add 2 <| 2 Or what example did you have in mind? Without right operators? - eastwing
  • yes, this is what I mean - user227049
  • can we continue the discussion in f # chat ? - user227049

1 answer 1

Understood with the help of Foggy Finger

The fact is that the reverse pipeline operators are also left-associative , and expressions are calculated from left to right, regardless of the presence of a reverse pipeline - which, by the way, is completely logical. Those. expression add 2 <| add 3 <| 4 add 2 <| add 3 <| 4 add 2 <| add 3 <| 4 should read wrong:

pass 4 to add 3 , and then pass the result to add 2

, and so:

in add 2 pass add 3 , then pass 4 to the result

In this particular example, I tried to pass a function (value of type int -> int ) to the place of an integer argument ( int ), which, of course, is an error. You can fix it, for example, like this: add 2 <| (add 3 <| 4) add 2 <| (add 3 <| 4) - in this case the result of addition will be transferred to add 2 , i.e. required integer.