Lesson 17. Design by composition—Semigroups and Monoids

After reading lesson 17, you’ll be able to

  • Create new functions with function composition
  • Use Semigroup to mix colors
  • Learn how to use guards in code
  • Solve probability problems with Monoid

In the preceding lesson, you looked at how sum types allow you to think outside the typical hierarchical design patterns present in most programming languages. Another important way that Haskell diverges from traditional software design is with the idea of composability. Composability means that you create something new by combining two like things.

What does it mean to combine two things? Here are some examples: you can concatenate two lists and get a new list, you can combine two documents and ...

Get Get Programming with Haskell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.