# What about computations with challenging framework?

What about computations with challenging framework?

In the event your nesting development cannot be utilized, we want an effective way to merge the brand new options that come with several or more monads in one formula. This is accomplished by doing calculations contained in this a monad where the values is actually themselves monadic philosophy in another monad. Such, we possibly may would computations regarding Continuation monad out-of kind of Cont (IO Sequence) a great if we need certainly to perform We/O into the computation on the Continuation monad. We are able to have fun with a beneficial monad out of method of Condition (Often Err an effective) a to merge the features of State and Error monads in a single calculation.

Envision a slight amendment to your example where i carry out the same I/O at first, but we possibly may wanted even more input in the middle of new calculation regarding Continuation monad. In this situation, we’ll let the user so you’re able to establish a portion of the yields worth in the event the type in worth is actually a certain variety. As We/O depends on part of the formula from the Continuation monad and you will area of the formula from the Continuation monad utilizes the result of the brand new I/O, we cannot make use of the nested monad trend.

As an alternative, we result in the formula on the Continuation monad have fun with viewpoints away from the new IO monad. Just what had previously been Int and you can Sequence values are actually away from form of IO Int and you can IO Sequence . We can not pull beliefs regarding IO monad – itâ€™s a single-means monad – so we may prefer to nest nothing perform-reduces of your own IO monad inside the Extension monad to control the values. I fool around with a helper function toIO to make it better whenever we are performing opinions from the IO monad nested when you look at the Extension monad.

## Example 20

Also which superficial analogy has gotten complicated and you may unappealing when we tried to merge some other monads in identical computation. It works, however it isn’t really prettyparing this new code top-by-top reveals the amount to which the fresh guidelines monad combination approach pollutes the fresh code.