7 A Type Safe Web App in Haskell

 

This chapter is to crystallize some of the concepts that were brought up in Chapter 5  and Chapter 6 . All that talk, saying that types are neat or that types help you out, will finally walk its walk. From the world of typing, we’ll see how letting the computer take care of much of the tedious bookkeeping homework helps us avoid boneheaded errors. And from the world of functional programming, we’ll see that structuring an app as (ultimately) one big function with one entry point avoids code spaghettification. That is, rather than having to hunt through a thicket of callbacks and indirection (spaghetti), we’ll be able to visualize "how we got here" much more easily.

These two factors, types and functional programming, help to transmute subtle domain errors ("I thought I had an AdminUser, but I actually had a GuestUser, oops") into honking-loud compiler errors. Bzzt, stop and fix it right now kind of stuff.

Provided that we do a little more thinking up front, we’ll spend less time hunting bugs. The whole edifice will snap together once all the types match up. And as an indirect effect, our programs will be easier to modify and extend later. So that’s the payoff.

7.1  Installation

7.2  Haskell Crash Course

7.2.1  Overall File Layout

7.2.2  Syntax

7.2.3  Strings, Lists, and Numbers

7.2.4  Defining and Calling Functions

7.2.5  Control Structures

7.2.6  Crash Course Summary

7.3  An Example Web Application in Haskell

7.3.1  Main

7.3.2  Ride Data Type

7.3.3  Web

7.3.4  Client-side

7.3.5  Generating Elm Code

7.4  Summary