Haskell has become the functional programming language of choice for many developers due to its excellent tools for abstraction and principled program design. The open source Clash hardware description language now brings these features to FPGA development.
Retrocomputing with Clash takes the experienced Haskell programmer on a journey into the world of hardware design with Clash. Our approach is based on using Haskell to its fullest potential, using abstractions like monads and lenses in building a library of reusable components.
But that wouldn't put the fun in functional programming! And so we put these components to good use in implementing various retro-computing devices:
- Pocket calculator
- Pong (sample chapter)
- A simple, but Turing-complete computer that uses Brainfuck as its machine code
- An implementation of the CHIP-8 virtual computer specification
- Intel 8080 CPU
- Space Invaders arcade machine
- Compucolor II, a home computer from 1977 complete with keyboard, color video, and a floppy drive
Not part of the book, but demonstrating its approach to developing fun FPGA designs with Clash, is Flappy Square from my Haskell eXchange 2022 talk.
I absolutely love the very Haskell approach to circuit design in this book, as opposed to my own write-Verilog-in-Haskell style. It leverages Haskell's type system in a very natural way to protect against many traps we as circuit designers often fall into.
The book clearly demonstrates the benefits of using a modern programming language for circuit design, where it builds reusable functionality and components at a far finer granularity than what I'm used to in traditional hardware description languages.
Another thing that's absolutely great is the book's use of SDL2 multimedia library to emulate peripherals like monitors which enables you to fully interact with the computers and games that you'll be building without having to go through the sometimes long and painful process of programming an FPGA.
– Christiaan Baaij, Clash lead developer, QBayLogic co-founder
This is the book for functional programmers looking to get into FPGAs and digital logic design. Learn Clash, the "I can’t believe it's not Haskell!" hardware description language, while indulging in nostalgia for the 1980s. Take a joyride through a variety of hands-on projects, including Pong, Space Invaders, and the Compucolor II, a personal computer based on the Intel 8080. Recommended.
– Miëtek Bak, mathematician
This book is a fascinating, knowledge-expanding work that leads to exciting domains. It is hard for me to believe that I can learn about low level designs through Haskell because it is a notoriously high-level language.
This language has been such a gift that has kept on giving.
Thanks to the clash-shake tool, I can run Haskell code on real hardware without prior knowledge of the FPGA toolchain.
– Tristan de Cacqueray, principal software developer
Where to buy
- Electronic version (PDF, e-book, and HTML) from Leanpub
- Print version from Lulu (Color hardcover edition)
- Print version from Lulu (B&W paperback edition)
Table of contents
Sample chapters
Hardware considerations
Code from the book
- retroclash-lib: Library of code shared between repositories, available from Hackage
- retroclash-sim: Library of simulation code shared between repositories, available from Hackage
- clash-shake: Shake build system rules for driving hardware synthesis from Clash all the way to FPGA bitfile, supporting Xilinx, Intel and SymbiFlow toolchains
- Calculator
- Pong
- Brainfuck computer
- CHIP-8
- Intel 8080
- Space Invaders
- Compucolor II
- All the rest: smaller programs