What is the dot pipe ".|" operator in Haskell?
Asked Answered
B

2

6

I understand "." (dot) as function composition. I understand "|" (pipe) as "or," guard introduction syntax (from here ), but I saw an answer on http-conduits using ".|" that makes use of this operator in a way I do not understand.

The other references for conduits I have found, such as:

...suggest syntax like "$$", "$=", "=$=", "=$" for combining conduits in data flows.

What should I call this ".|" this operator and how does it work?

Predictably, googling for ".| haskell" or "'dot pipe' haskell" or "'dot pipe' haskell operator conduits" were not very successful.

Barthold answered 3/12, 2016 at 23:17 Comment(0)
B
9

This is just the (recent) new syntax that conduit uses for fusion. The author wrote a blog-post about this not long ago. To quote from the post, he proposed (and eventually did this) to

Replace the $=, =$, and =$= operators - which are all synonyms of each other - with the .| operator. This borrows intuition from the Unix shell, where the pipe operator denotes piping data from one process to another. The analogy holds really well for conduit, so why not borrow it? (We call all of these operators "fusion.")

As an aside, if you ever need to look up operators, Hayoo and Hoogle are the places to go. There is also Stackage Hoogle (thanks @duplode) which lets you look up operators for particular resolvers (which is especially useful here since this is a recent change).

Bazooka answered 3/12, 2016 at 23:21 Comment(4)
Stackage Hoogle is also a nice option -- it defaults to a broader range of packages than the haskell.org one.Proselytism
Thanks, @Alec. If you'll continue to indulge me, I propose we continue these until our stackoverflow Q&A sessions overcome all of the obsoleted and deprecated syntaxes and strategies in older versions and implementations available elsewhere on the internet, and these become top hits to direct people canonically to the correct documentation. :)Barthold
seems like they'd be better calling the operator "pipe" :/Delciedelcina
Hmm, off to a good start: after one hour, this is now already the top google result for "dot pipe haskell" a phrase I've now written an additional time so folks will be properly redirected to Michael Snoyman's announcement of this syntax linked to in this answer.Barthold
M
1

.| is introduced by the Conduit library and is a synonym to fuse.

fuse
  :: Monad m => Conduit a m b -> ConduitM b c m r -> ConduitM a c m r

fuse is used for composition of conduits the same way as . operator is used for composition of functions. Finally, .| is a new syntax to replace $=, =$, and =$=, which were synonyms anyway.

Morrill answered 4/12, 2016 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.