-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Proposal
Add the |> pipe operator to the Data.Function module, similar to the already existing &:
infixl 0 |>
(|>) :: forall r a (b :: TYPE r). a -> (a -> b) -> b
x |> f = f x
{-# INLINE (|>) #-}
⚠️ There's a difference between|>and&:&has fixityinfixl 1while I propose for|>to have fixityinfixl 0(same priority as$). Having the same priority results in a compilation error when using both$and|>together in a single expression. This is intentional because the flow can be extremely confusing. For example, when writingf $ x |> g(orf $ x & gcurrently) it's not immediately clear from just looking at the code whether it'sg (f x)orf (g x).
ℹ️ I'm proposing to add this operator only to the
Data.Functionmodule and notPreludeto avoid massive breaking changes which are not justified at this point.
Motivation
Haskell is one of the oldest Functional Programming languages that are still actively used nowadays. It inspired multiple features in many other programming languages. And I believe it's time for Haskell to take expiration from more modern FP langs.
Specifically, the pipe application operator |> (and sometimes <|) is popular in other FP languages while Haskell remains almost the only language that uses $ and &.
These are quite popular languages that use or want to add <| or |> (the list might not be exhaustive):
In fact, Haskell itself has several libraries that reimplement these operators:
And some libraries reimplement |> in their internals:
Here are some people on Twitter who like using the flow library or forward style of application:
According to the Haskell2010 report, one of the Haskell goals is:
- It should reduce unnecessary diversity in functional programming languages.
I strongly believe that having $ and & while the rest of the world uses <| and |> is exactly that unnecessary diversity, so adding these two operators to base will help to reduce this while not conflicting with other goals (and, in fact, it might even help! Lots of people find $ and & confusing for various reasons, having <| and |> can improve Haskell teaching and learning experience).