Tag Archives: multithreading

Simon Already Did It!

Science and industry are bubbling with exciting new computational techniques. Parallel processing, quantum computing, GPU processing, software transactional memory. Proof-of-concept programming languages are mushrooming, but Simon already did it.

Simon Peyton Jones’ crazy academic language Haskell can do all of these things. The Hackage repository has packages for parallel processing, quantum computing, GPU processing, and software transactional memory. If there’s a buzz on some new computational technique, Haskell already did it. It’s an incredibly flexible prototyping system.

How does Haskell do all of these things when typically, each of these techniques is explored using an extremely limited prototype language? Haskell is a functional language with powerful domain specific language capability; you no longer need to trade research papers in a dozen languages when it’s easy to prototype an experimental language within Haskell.

DSLs are featured in Lisp; what makes Haskell so special? The secret sauce is declarative programming: In Haskell, the coder describes the computation to be performed, and the Haskell compiler decides an optimal way to perform the computation. Imperative programming is eschewed in favor of pure functional programming: mapping, composition, recursion. By using single assignment and avoiding state, Haskell gains flexibility in how it executes code.

Haskell does event driven computing, concurrent computing, matrix computing, even lazy computing, by isolating imperative code in monads. There are monads for pseudorandom number generation, monads for I/O, monads for multithreading. The accelerate package for behind-the-scenes GPU computing is just a monad that turns Haskell vector manipulations into CUDA, executes it on a GPU, and returns the Haskell-typed result.

The final ingredient is generalized abstract data types. When you create a data type to model something in the real world (employee IDs, aquarium fish, highway traffic, etc.), Haskell can derive how to print and parse the models from text files to live objects and back. It can determine on its own how to compare and sort sequences of data. Finally, Haskell can automatically manipulate arbitrarily complex collections of data (databases of employee IDs, store rooms of aquarium fish, graphs of graphs of graphs of highway traffic). A bloom filter of schoolmates? No problem.

There is no longer a need to learn Unified Parallel C, QCL, CUDA, libev, or MATLAB. Haskell already did it; just learn one language that can handle all these paradigms and paradigms yet to be invented. There are many free online tutorials that enable you to use graduate level techniques with an undergraduate’s knowledge. Haskell’s language prototyping flexibility makes C look like Brainfuck: you’ll still succeed, but wouldn’t you prefer to do it with more robust, more expressive tools?