What happens to you if you break the monad laws?

The monad laws are simply additional rules that instances are expected to follow, beyond what can be expressed in the type system. Insofar as Monad expresses a programming pattern, the laws are part of that pattern. Such laws apply to other type classes as well: Monoid has very similar rules to Monad, and it’s generally … Read more

When would I want to use a Free Monad + Interpreter pattern?

As mentioned in the comments, it is frequently desirable to have some abstraction between code and database implementation. You can get much of the same abstraction as a free monad by defining a class for your DB Monad (I’ve taken a couple liberties here): class (Monad m) => MonadImageDB m where indexImage :: (ImageId, UTCTime) … Read more

What exactly makes Option a monad in Scala?

Monad is a concept, an abstract interface if you will, that simply defines a way of composing data. Option supports composition via flatMap, and that’s pretty much everything that is needed to wear the “monad badge”. From a theoretical point of view, it should also: support a unit operation (return, in Haskell terms) to create … Read more

Is Haskell truly pure (is any language that deals with input and output outside the system)?

Take the following mini-language: data Action = Get (Char -> Action) | Put Char Action | End Get f means: read a character c, and perform action f c. Put c a means: write character c, and perform action a. Here’s a program that prints “xy”, then asks for two letters and prints them in … Read more

Using return vs. not using return in the list monad

To see why you get the particular answers that arise, the desugaring explanations are very helpful. Let me supplement them with a little general advice about developing perceptions of Haskell code. Haskell’s type system makes no distinction between two separable “moral” purposes: [x] the type of values which are lists with elements drawn from x … Read more

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