I'm trying to figure out monads in Haskell but didn't get too far yet.
I found https://en.wikibooks.org/wiki/Haskell/Understanding_monads#cite_note-1 and several other tutorials/explanations, but none seems to be explaining the difference between the type constructor and the return function.
As I understood the
- type constructor constructs a monad from a given value of the basic data type. So it's sort of a normal constructor like in Java, which builds from the given parameter a new instance.
returnfunction applies the type constructor on the given value of the basic data type and returns the constructed monad.
So what's the point of having two functions doing basically the same?
EDIT So using the example of a Maybe-monad, the
country = Just "China": (constructor) creates the monad for the value "China".return "China": returns the monad which is corresponding to the value of China, so it's basically the monad containing the"China"value.
Generally speaking I understand a monad as a container for values. One usage of monads is to combine simple/existing computations to more complex computations.