Scala for-comprehensions and Monads

Scala

  • Scala has had for-comprehensions from the beginning, but not always higher-kinded polymorphism[8].

  • What C# calls SelectMany and we have called bind, Scala calls flatMap.

  • Like LINQ, for-comprehensions provide syntactic sugar for calls to flatMap (and others) and also like LINQ are not type-safe[9].



[8] Scala By Example (DRAFT October 28, 2009) still incorrectly states that Scala's type system is too weak to express the generalisation.

[9] This is because of historical reasons, unlike C#/LINQ, which is due to type system limitations.