1

In F# you have the backward pipe operator <|, which like its brother |> serves as a way to pass parameters into functions...

Now I already understand the great idea behind having |>, letting the programmer easily see the value affected rather than having to go through a chain of nested function calls is awesome and looks beautiful:

let newList = someList
                |> List.map (fun x -> x * 3)
                |> List.filter (fun x -> x > 12)

So my question is, if functions are called like funcName param anyway, what's the point of having funcName <| param?

I've also seen some write functions like this func1 <| value |> func2 what exactly does that do?

Electric Coffee
  • 11,733
  • 9
  • 70
  • 131

1 Answers1

6

It exists to avoid parentheses, similarly to $ in Haskell. See section Function application with $ in Learn You a Haskell.

thSoft
  • 21,755
  • 5
  • 88
  • 103
  • 3
    Notice that `$` is right-associative, while `<|` is left-associative. – Ramon Snir Oct 08 '13 at 12:46
  • What kind of impact would that make? – Electric Coffee Oct 08 '13 at 12:52
  • 1
    @ElectricCoffee The parser would read the code in a different order, so at best you'll get type-related errors, and at worst, the code will type-check then execute in a different order at run-time. – Jack P. Oct 08 '13 at 13:09
  • 3
    It's the difference between `raise (InvalidOperationException("Don't do that!"))` and `raise <| InvalidOperationException("Don't do that!")` In some cases a backwards pipe is less irritating than wrapping an entire expression in parens. – Joel Mueller Oct 08 '13 at 23:01