Happy Learn Haskell Tutorial Vol 1

Buy now at Leanpub

Please Buy now at Leanpub

Written and illustrated by GetContented.

Published on 2016-05-20.


Contents

Main Table of Contents
Previous chapter: 11. More Shopping
12. How To Write Programs
Next chapter: 13. At The Zoo

12. How To Write Programs 🔗

At this point, we’ve seen enough Haskell in actual programs that we can start to level up our learning to the next stage: adjusting and writing extremely simple programs.

We haven’t yet seen all of Haskell’s basics even once through yet, though, so we continue our tour of reading basic programs as we do.

A warning at this point: as Han-Solo says to Luke in Star Wars: “Don’t get cocky, kid!”

That is, don’t try to do too much at this point and don’t expect too much from yourself. Just proceed little by little. Build up piece by piece. Before you know it, you’ll be at a point where you can write small but enjoyable programs, and you’ll know how to begin to find things for yourself when you don’t know!

In other books, writing programs is often left as an exercise for the reader to work out how to do, but this doesn’t sit well with us, and it usually doesn’t work very well, either.

We prefer to guide you, because the task of problem solving is not necessarily obvious. In order to write a program, one strategy is to pull the problem its trying to solve apart into smaller pieces. This is called step-wise refinement, or top-down design.

We can also go the other way: (Bottom-up design, obviously!) start with the things we already know we can do. Smaller, known pieces, then build up with those to form larger and larger pieces by combining them until we have our complete program.

Professional programmers use both of these strategies all the time to piece programs together and solve problems.

Haskell is very good at helping us to do both of these things. Its type system shows us where things match up, and its functional nature lets us easily separate data from code which keeps things free to be reused, re-combined and composed.

We use processes called equational reasoning, function extraction, dummying, black-boxing (otherwise known as encapsulation) and refactoring to do these strategies; identical processes that software professionals use every day to get their work done, sometimes without realising it.

Let’s continue.


If you’ve enjoyed reading this, please consider purchasing a copy at Leanpub today

Please follow us, and check out our videos Follow @HappyLearnTutes

Also, Volume 2 is now in beta and being written! Show your support and register your interest at its Leanpub site.


Main Table of Contents
Previous chapter: 11. More Shopping
12. How To Write Programs
Next chapter: 13. At The Zoo