Progressions of concision

January 30, 2016


Let's implement a simple sum type, Either, in a few polymorphic languages.

Language Source Lines of code
Java 75
Scala Either.scala 3
Haskell Either.hs 1

Composable disjunction

Either is useful for storing a value of one of two types, but it isn't very useful otherwise.

Let's make it composable by adding map, ap, and flatMap (a.k.a. fmap, <*>, and >>=), and biasing it to the right.

Language Source Lines of code
Java 102
Scala RightBiasedEither.scala 15
Haskell RightBiasedEither.hs 9