Haskell Quick Syntax Reference by Stefania Loredana Nita & Marius Mihailescu

Haskell Quick Syntax Reference by Stefania Loredana Nita & Marius Mihailescu

Author:Stefania Loredana Nita & Marius Mihailescu
Language: eng
Format: epub
ISBN: 9781484245071
Publisher: Apress


The Three Rules

You have seen that a monad must follow three rules: right unit, left unit, and associativity. These three rules show you the relation between a computation, the return function, and the binding operation.

All monads are instances of the Monad type class from Prelude, which is defined as follows:class Monad m where

return :: a -> m a

fail :: String -> m a

(>>=) :: m a -> (a -> m b) -> m b

(>>) :: m a -> m b -> m b

In this definition, the last rule can be expressed in terms of the third rule. Note that (>>=) is read as “bind,” and (>>) is read as “then.”

Before going further, we need to mention that the do notation works great with monads; it acts as syntactic sugar for operations. You will see some examples in the next sections.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.