Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The pipe & filter architectural pattern is defined as a chain of processing elements, arranged so that the output of each element is the input of the next. Every example seems to consider inter-process or inter-thread connection performed through some kind of shared buffer.

To me, it seems that Haskell function composition is performing the same task. Can we say that it is an instance of this pattern even if it is just about function ordering and no explicit buffer is use as pipe? If yes, can we say the same thing for non-lazy language?

share|improve this question
up vote 7 down vote accepted

They are connected, but the connection is the other way around (sort of).

Morphism composition in an appropriate category accurately models both function composition (where the category is Set for a strict language and CPO for a lazy language) and process composition (where the category is the (AFAIK, unnamed) category where the objects are strings , morphisms are shell processes, and composition is the pipe operator). Shell processes can be seen, without loss of either generality or accuracy, as (lazy) functions of type String -> WriterT String IO String, and pure functions of type String -> String can be losslessly converted to and from functions of type String -> Identity String, so both are really just (>>=) in disguise.

share|improve this answer
What is a CPO category? My google-fu is weak :( – Andres F. Jun 13 '13 at 21:44
@AndresF. The category of Complete Partial Orders. – Ptharien's Flame Jun 14 '13 at 2:28

There is a difference. Pipes and filters deal with data and data connections, whereas Haskell Function Composition deals with first-class functions. First-class functions are composable in ways that pipes and filters are not.

Further Reading
What does composability mean in context of functional programming?

share|improve this answer
Composition doesn't necessarily deal with first-class function so much as composition is itself a first-class function. Take for instance the composition of the function ++, where composition is ., ++ . ++ would take a value and return that value incremented twice, but ++ is not a first-class function, it only takes a value and returns a value. The composition function is the first class function which takes two functions and returns one. – Jimmy Hoffa Jun 25 '13 at 17:18
@JimmyHoffa, I think you are confusing the notion of 'first-class function' with 'higher-order function'. When a language has 'first-class functions' it treats functions the same as it treats other first-class data types; they can be passed to and returned from functions, stored in data structures, etc. A higher-order function takes advantage of the first-class nature of functions by taking function parameters and/or returning function values. – Levi Pearson Aug 14 '13 at 17:32
@LeviPearson yeah, I must have accidentally put my brain in sideways when I got up the morning I wrote that comment. If you're going to keep poking around here writing good content for P.SE, ponder idling in P.SEs general chat – Jimmy Hoffa Aug 14 '13 at 17:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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