Refactoring the CSV program

  • Semigroup in Prelude
  • Parts of main
  • Process-and-print
  • Specialization
  • Where
  • Count and filter
  • Range type
  • A list of ranges
  • Process, then print
  • With input
  • Read, decode, fail
  • Day parsing
  • Crashing concern
  • Interpret, filter, group
  • Zipping ranges with numbers
  • Error aggregation
  • Failure values
  • Using the header
  • Final result

The original program was one of the first things I ever produced in Haskell, and it looks very different from something I’d write today. In this lesson, I walk through the process of cleaning it up, thinking carefully about what makes a well-designed program.

A few of the general ideas covered here:

  • Splitting up long definitions
  • Separating pure functions from I/O
  • Avoiding the use of partial functions
  • Printing aggregated error information

Sign up for access to the full page, plus the complete archive and all the latest content.