Reading through the documentation of Control.Monad I found such description of mapM:
Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results
I'm interested, what does “element of a structure” mean for an arbitrary monad? E.g, State
or IO
monad? What a structure?
I know what mapM
function does and interesting more in the semantics of this particular words in the description of mapM
. Does this "structure" somehow connected with the notion of "algebraic structure"?
Structure is a set with one or more finitary operations defined on it that satisfies a list of axioms.
If so then what are the elements of this structure (carrier set) as I asked for e.g. IO monad? In general?
"Element of a structure" means exactly nothing for an arbitrary monad, because it doesn't reference the monad. The mapM
you're referring to is a member of the Traversable
typeclass, and the structure it refers to is the Traversable
. A Traversable
is a data structure that can be mapped over, such as a list or a tree. "Element of a structure" refers to the list's elements.