I am trying to find which language used the |> operator first.

It's being discussed for use in R, and it's been in OCaml for some years.

Did it originate in OCaml? If not, what are its earliest origins and use?

  • 1
    Is this about an old enough operator to be retrocomputing? R and Ocalm are both relatively new languages compared to what we usually discuss here. The question doesn't seem to be about pipes in generally, but the specific use of '|>' as operator in programming languages. – UncleBod Dec 17 '20 at 8:08
  • 1
    @UncleBod it is true that it's about the |> specifically. There has been some discussion about where such questions ought to reside on meta – stevec Dec 17 '20 at 8:11
  • From here, there is suggestion that these languages may also have the same / similar pipes: F#, OCaml, Elixir, Elm, Julia, Hack, and LiveScript. – stevec Dec 20 '20 at 15:22

Douglas McIlroy wanted to introduce pipes already at the beginning of Multics project in 1964:

We should have some ways of connecting programs like garden hose -- screw in another segment when it becomes necessary to massage[sic?] data in another way.

But at least according to Wikipedia, they were implemented in Unix first.

The |> in OCAML and similar operators for point-free (i.e., not using variables, instead composing functions by pipes and other means) programming in other functional (and increasingly, non-functional) languages go back at least to the seminal article Can programming be liberated from the von Neumann style? by John Backus (you may have heard of Backus-Naur-Form or BNF) from 1978.

If the question is meant more as "why was specifically |> chosen", it's important to keep in mind that in OCAML, infix operators have to start with certain symbols, and the precedence of the operator is determined by the initial symbols (see e.g. here).

That's why the choice of operators in OCAML is very different from, e.g., Haskell, where there is a whole zoo of left and right application and composition operators, for pure functions, monads, categories, and other structures.

Even though the operation itself is the same.

  • Multics/Unix pipes are a fundamentally different thing to functional programming pipelines. While Backus's paper may have introduced the concept, I don't believe the specific notation is that old, which I believe is the point of this question. In fact I believe the left-to-right style that |> enables is relatively modern - older functional languages may allow point-free style, but the flow of data is usually right to left, as in standard mathematical function notation (the compose operator is usually f . g meaning "do g then perform f on the result; |> does it the other way around). – occipita Dec 17 '20 at 10:27
  • @occipita "Multics/Unix pipes are a fundamentally different thing to functional programming pipelines." They are not. The name "functional programming pipelines" already gives that away, and Unix pipes were and are frequently used to explain the concept to functional programming newbies. If the question is about the symbol | and not about the concept, then I guess the symbol | originates with Unix (and that was probably an influence to choose |> in OCAML). – dirkt Dec 17 '20 at 10:32
  • @occipita And yes, left-to-right vs. right-to-left is the reason you sometimes need operators. But the left-to-right vs. right-to-left discussion is also a lot older, in mathematics both function application on the right (or even as a sort of superscript) and composition in "natural order" instead of the usual "reverse order" has been used by specialists for a long time, though you'll likely never come across these in mainstream mathematics. – dirkt Dec 17 '20 at 10:35
  • 3
    I don't know who added the [sic?] but if anyone is confused massage in this case is synonym for transform – Aaron Dec 18 '20 at 9:45

Pipes have been a feature of Unix and Unix shell programming since the the first Unix shell was introduced between 1971 and 1975.

  • 2
    Thanks @Fred. I think Unix and Unix shell used | pipe operator only? (I could be wrong). Do you know when the first pipe that looked like this |> emerged (and which language/system it was on)? – stevec Dec 17 '20 at 8:05

vbar is used for a number of different uses, some keyboards have two variants of it ¦ and ̄

In IBM languages like APL, it is used for logical or (true if either or both). IBM were dissenters against a common ASCII code for this reason.

In written maths, | can also mean 'divides', so 5 | 15 means that five goes into 15 an integer number of times.

In the BNL markup form | gives a range of equal options, in 'radio-button' style (exclusive or), so answer = yes | no .

in REXX (1980s), it comes to mean logical or singularly, or concatinate double.

You will probably find it goes back as far as the character used to divide tables, ie a vertical rule in a set of type. This is why it's in CP 437.

  • It’s in CP 437 because it’s in ASCII (character code 124). – Stephen Kitt Dec 17 '20 at 13:21
  • But in the defing of ascii, IBM were descenters due to the multiple use of pipe. If you look at the EBCDIC code page, it provides for multiple pipes (broken and full), because languages from the 1960s (COBOL &c), were using these differently. – wendy.krieger Dec 17 '20 at 13:48
  • Yes, I get that, but you wrote “This is why it's in CP 437”; it’s not special to CP 437, it’s part of ASCII, of which CP 437 (along with many other code pages) is a superset. – Stephen Kitt Dec 17 '20 at 13:54
  • BrokenPipe is part of ascii, whereas pipe also occurs at 0xA9, where it doubles as a table-drawing instrument. 437 was what IBM designed for the first PC. – wendy.krieger Dec 17 '20 at 14:05
  • 2
    The question is specifically about the |> character sequence, not about every single use of a vertical line character. – user3840170 Dec 17 '20 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.