3 ms·
I see a monad as just an interface, as in a set of generic functions with specific type signatures that you can overload with different types. The functions bei
by newen 8y ago
I see a monad as just an interface, as in a set of generic functions with specific type signatures that you can overload with different types. The functions being identity : a -> m a, and bind : m a -> (a -> m b) -> m b. The type m you use should have some specific properties but it's not like you can enforce these properties in haskell.
It's nice for use in haskell since it combines well with the do notation, allowing for an imperative programming style primarily when you use the IO monad. The do notation basically converts into a sequence of bind and return operations, so that it's impossible to call print a second time on an IO object while having reference to the same IO object that you called print the first time on. This is needed because you can't make a copy of the IO object.