“Magical Haskell” chapter 1 is ready

J Ho
Superstring Theory
Published in
2 min readNov 4, 2017

I got some very interesting and in-depth responses to the previous piece on teaching haskell, so worked on my notes and finished a draft of the 1st chapter of “Magical Haskell” (permanent page for the whole book — very much a work in progress now — is here on leanpub). Thank you very much to all who contributed, and please read and provide feedback to the first chapter, too — here, on leanpub, or drop me an email! Short excerpt is below.

Functional problem solving

Typed functional programming is just like magic. Your spells are functions — they turn something into something else (like pigs to Ferraris or strings to numbers) or produce some effect (like putting Ogres to sleep or drawing a circle on the screen), and you need to combine different spells in the right order to get to the desired result.

What happened in the story above was dynamically typed magic: you used a spell that works only on pigs on a horse instead and your “program” crashed, killing the horse in the process (that’s what often happens with JavaScript programs). With the statically typed magic, that we will use from now on, a powerful being called Typechecker would see your mistake, stop your hand, and would tell you that “Gimmeraree” expects a pig as its’ input — which would indeed make you a much more powerful and successful mage than if you go around killing other people’s horses.

In a very short time, starting with barely anything but an empty set, we have come up with the concepts of:

- Types, inhabited by their members, also called values, and introduced two very simple types: Int and Char

- Functions, which map values of one type to values of another (or the same) type

- Type Functions, which create new types from other types, and introduced a couple of useful complex types: String and ListInt

- Composition, an essence of a functional program (and, incidentally, Category Theory, but we won’t be going there for quite some time yet)

This is pretty much everything we need to gradually build our magical Hask world!

--

--