3 ms·
What do you mean by specialized? Don't know the equivalent of flatten in Haskell, but if you want a signature then it is something like: def flatten(m: M[M
by bad_user 12y ago
What do you mean by specialized?
Don't know the equivalent of flatten in Haskell, but if you want a signature then it is something like:
def flatten(m: M[M[A]]): M[A]
Or another way of thinking about it ...
flatten(m) == flatMap(m)(x => x)
So basically, in order to define a monad, implementing flatMap is equivalent to implementing flatten. And I think that "flatten" as a verb is very intuitive, although intuitiveness is subjective since it's tightly related to familiarity - but flatten has been used in many languages as an operation available for collections and it works for monads in general just as well.
- dllthomas 12y agoSpecialized in the sense of a more restricted type. From your answer, it seems like "no" - though my Scala is superficial and rusty. The Haskell equivalent is join :: Monad m => m (m a) -> m a We also have the equivalent specialized to lists: concat :: [[a]] -> [a] And as you say, join = bind id = (>>= id). Incidentally, in math that function is the "eta" in the triple representing a monad.