Functional manipulation of bit streams

Per E. Gustafsson, Konstantinos Sagonas · 2008

SUMMARY Writing code that manipulates bit streams is a painful and error-prone programming task. Currently, it is often performed via bit twiddling techniques based on using explicit bit shifts and bit masks in buffers explicitly allocated and managed by the programmer. Still, this kind of programming is commonplace in many applications ranging from decoding streaming media files to implementing network protocols. In this article we show how high-level constructs from functional programming, such as pattern matching and comprehensions, can make bit stream manipulation more succinct, less error-prone, and totally memory-safe. We formally define these language constructs and show a variety of example uses from several different application areas. We also describe how these constructs have been implemented efficiently in the functional programming language Erlang. The resulting performance is superior to that of other (purely) functional languages and competitive to that of low-level, unsafe languages such as C.

Read the paper · More papers on PaperTik