Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • https://docs.google.com/presentation/d/1RBefOCZ7AKOo4f1yiF4mtKPAT3l5vY9ky2SR02O4Vvg/edit#slide=id.g3c22e35a9_0205
  • http://www.yesodweb.com/blog/2014/03/network-conduit-async

...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.

like image 231
Mittenchops Avatar asked Dec 03 '16 23:12

Mittenchops


Video Answer


2 Answers

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).

like image 147
Alec Avatar answered Oct 18 '22 13:10

Alec


.| 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.

like image 41
penkovsky Avatar answered Oct 18 '22 13:10

penkovsky