Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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?

Licencié sous: CC-BY-SA avec attribution
scroll top