Reputation: 22244
Please help confirm or correct the understandings of what Monad is and its traits.
In my understanding, a Monad is:
There need to be a return or unit interface to create a Monad of type T.
unit:= T -> M[T]
In Scala, List() or Set() are the examples of return interface, and any Scala sequence types (Array, List, Map, String) are Monad which provide flatMap interface which is bind.
Are these correct?
Software engineering provides ways to manage complexity or to structure software, such as Structured Programming without goto, UNIX pipe to pipeline transformation, Object Oriented to encapsulate data & control access, etc.
Is Monad a design pattern providing a way to structure a computation as a chain?
I suppose UNIX commands e.g. cat, grep are functions that can be chained but it does not mean they are Monad, and they are not Monad because they do not have return/unit nor they are not data type. Or is it still regarded e.g. IO Monad as in Monadic i/o and UNIX shell programming?
I believe there is no bind or Scala flatMap equivalent in Python out of the box. Can I say Python does not have Monad feature out of the box?
Upvotes: 1
Views: 268
Reputation: 71
Yes, you're right about those interface things. However, it is noteworthy that in abstraction, a monad should have two adjunctive methods which can be composed to chain the computations. Note that flatMap is simply the composition of such methods - flat and map. map can be used to define a computation of type M[A] -> M[M[B]] and flat which is used to define M[M[B]] -> M[B].
Yes, in Scala they're a means to chain computations.
The shell script commands may fulfil the purpose of the monads (in the considered analogies) but still can't be regarded as monads (by me at least) as they don't necessarily comply with point 1.
Yes, the monads are NOT supported out-of-the-box in Python. One has to rely on the nested loops only.
Upvotes: 0