concept Monad type class in category haskell

appears as: Monad type class, The Monad type class
Get Programming with Haskell

This is an excerpt from Manning's book Get Programming with Haskell.

Maybe is also a member of the Monad type class and therefore can also use do-notation. Suppose that rather than getting your pizza values from user inputs, you had to retrieve these values from two Maps: one with sizes and one with costs. Here’s a nearly identical program to the one you just wrote using Maybe. Rather than getting your info from a user, you’ll look up the cost of a pizza by ID in a costData Map.

In this lesson, you’ll look at the final evolution of this process, the Monad type class. Through one more operator, the Monad type class will allow you to perform any arbitrary computation in a context you’d like. You already saw this power in unit 4 with do-notation, which is syntactic sugar for the methods of the Monad type class.

Listing 30.1. A quick reminder of do-notation
main :: IO () main = do putStrLn "Remember do-notation!" putStrLn "It makes things easy!"

To understand why you need the Monad type class, you’ll ignore do-notation for this lesson and see why you need Monads at all, given how powerful Functor and Applicative are. Because do-notation does make life much easier, you’ll revisit it in the next lesson.

Figure 30.4. This is the only pattern you need a solution for; the Monad type class provides an answer.

In this lesson, our objective was to introduce you to the Monad type class. The Monad type class is the final refinement of computing in a context that you started with Functor. The most important method of the Monad type class is the >>= (pronounced bind) operator. You use >>= to chain together functions of the type (a -> m b). This is particularly important for working with the IO type. Unlike Maybe, you can’t trivially use pattern matching to access values inside the IO context. The Monad type class is what makes I/O programming possible. Let’s see if you got this.