Re:Monoids, Functors, Applicatives, and Monads: Main Ideas
by dllthomas on Monday January 05, 2015 @01:22PM
(#8840208)
I don't know enough Scala... "flatten" seems to be equivalent to "join" from Haskell/math - is "flatten" specialized to lists? For that matter, is "map"?
[ Parent
| on HN ]
Re:Monoids, Functors, Applicatives, and Monads: Main Ideas
by bad_user on Wednesday January 07, 2015 @05:52AM
(#8849833)
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.
Re:Monoids, Functors, Applicatives, and Monads: Main Ideas
by dllthomas on Wednesday January 07, 2015 @11:47AM
(#8851532)
Specialized 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.