| Start |
|---|
| No general way to extract value from a monadic computation You can wrap values into actions and pipe the result of one computation into another: However, the definition of a Monad doesn’t guarantee the existence of a function of type That means there is, in general, no way to extract a value from a computation (i.e. “unwrap” it). This is the case for many instances: Specifically, there is no function |
| Monad as a Subclass of Applicative As of GHC 7.10, It is obvious that This function is defined as Thus if you have already defined an instance of As with the monad laws, these equivalencies are not enforced, but developers should ensure that they are always upheld. |
Definition of Monad The most important function for dealing with monads is the bind operator
The other function defined by Its name is unfortunate: this
|
| The Maybe monad
Consider the following function: Think of How do we
and now we can write: Kleisli composition There are three monad laws that should be obeyed by every monad, that is every type which is an instance of the where Or equivalently, using the Obeying these laws makes it a lot easier to reason about the monad, because it guarantees that using monadic functions and composing them behaves in a reasonable way, similar to other monads. Let's check if the
|
| IO monad There is no way to get a value of type An expression of type Not surprisingly, The things you can do to expressions of type More from the Haskell Wiki on the IO monad here (opens new window). |
| List Monad The lists form a monad. They have a monad instantiation equivalent to this one: Or equivalently, using we obtain: |
| do-notation
|
Read Article
https://develop.horje.com/learn/1434/reference