Skip to Content
Mastering Functional Programming
book

Mastering Functional Programming

by Anatolii Kmetiuk
August 2018
Intermediate to advanced
380 pages
10h 2m
English
Packt Publishing
Content preview from Mastering Functional Programming

Monoid

Monoid is another popular type class that you will frequently encounter in practice. Basically, it defines how to combine two data types.

As an example of Monoid, let's take a look at the implementation of an Applicative type class for the Either data type. In the previous section, we were forced to use a specific version of Either, the one with Left set to a list of strings. This was done precisely because we know how to combine two lists of strings, but we do not know how to combine any two generic types.

If we define the signature of this preceding Applicative as follows, then we will not be able to provide a decent implementation of this function because we will not be able to combine two generic types:

implicit def applicative[L]: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781788620796Supplemental Content