What is the point of the class Option[T]?

You’ll get the point of Option better if you force yourself to never, ever, use get. That’s because get is the equivalent of “ok, send me back to null-land”. So, take that example of yours. How would you call display without using get? Here are some alternatives: getPerson2 foreach (_.display) for (person <- getPerson2) person.display … Read more

Monads as adjunctions

Edit: Just for fun, I’m going to do this right. Original answer preserved below The current adjunction code for category-extras now is in the adjunctions package: http://hackage.haskell.org/package/adjunctions I’m just going to work through the state monad explicitly and simply. This code uses Data.Functor.Compose from the transformers package, but is otherwise self-contained. An adjunction between f … Read more

Monads with Java 8

Just FYI: The proposed JDK8 Optional class does satisfy the three Monad laws. Here’s a gist demonstrating that. All it takes be a Monad is to provide two functions which conform to three laws. The two functions: Place a value into monadic context Haskell’s Maybe: return / Just Scala’s Option: Some Functional Java’s Option: Option.some … Read more

mtl, transformers, monads-fd, monadLib, and the paradox of choice

A bunch of them are almost completely equivalent: mtl uses GHC extensions, but transformers is Haskell 98. monads-fd and monads-tf are add-ons to transformers, using functional dependencies and type families respectively, both providing the functionality in mtl that’s missing from transformers. mtl-tf is mtl reimplemented using type families. So essentially, mtl == transformers ++ monads-fd, … Read more

Confused with the for-comprehension to flatMap/Map transformation

TL;DR go directly to the final example I’ll try and recap. Definitions The for comprehension is a syntax shortcut to combine flatMap and map in a way that’s easy to read and reason about. Let’s simplify things a bit and assume that every class that provides both aforementioned methods can be called a monad and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)