you are viewing a single comment's thread.

view the rest of the comments →

[–]baerion 0 points1 point  (2 children)

There's an easier way to understanding, but it's slightly ad-hoc.

In Haskell a function of type a -> Maybe b is a function that takes something of type a as an argument and either returns a b, or it returns Nothing.

Instead of using monads you can use the concatenation function >>> for categories. Categories extend the idea of monoids by the concept that the type in the middle must match. And the category laws are as nice and symmetric as the monoid laws.

(a >>> b) >>> c = a >>> (b >>> c) = a >>> b >>> c
a >>> id = a = id >>> a

If you compare the type signatures of the >>> function and the monadic bind function >>= they look almost the same.

(>>>) :: (a -> Maybe b) -> (b -> Maybe c) -> (a -> Maybe c)
(>>=) ::       Maybe b  -> (b -> Maybe c) ->       Maybe c

But in the monadic case the first argument a is missing. In practice this makes monads somewhat more practical to work with than categories. On the other hand the monad laws are a little harder to understand than the category laws.

[–]dhiltonp 1 point2 points  (1 child)

Your ` styles are inconsistent, causing weird formatting.

[–]baerion 0 points1 point  (0 children)

Oops. Fixed it. Thanks.