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

Implementation for Either

Now that we have familiarized ourselves with Monoid and had a look at how it is used in the context of simple types such as integer, let's take a look at our previous example, the example of Either with a generic type of LeftEither[L, A]. How can we define the Applicative instance for a generic Left type? Previously, we saw that the body of the ap function for a generic Left type is not very different from the body of this function for the list. The only problem was that we didn't know how to combine two arbitrary types.

This combination sounds like exactly the task for Monoid. So, if we bring the implicit dependency on Monoid into scope, we can define the ap and Applicative type class for the Either type as follows: ...

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