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

What are the definitions for >>= and return for the IO monad?

There is no specific implementation for IO; it’s an abstract type, with the exact implementation left undefined by the Haskell Report. Indeed, there’s nothing stopping an implementation implementing IO and its Monad instance as compiler primitives, with no Haskell implementation at all. Basically, Monad is used as an interface to IO, which cannot itself be … Read more

Monad equivalent in Ruby

The precise technical definition: A monad, in Ruby, would be any class with bind and self.unit methods defined such that for all instances m: m.class.unit[a].bind[f] == f[a] m.bind[m.class.unit] == m m.bind[f].bind[g] == m.bind[lambda {|x| f[x].bind[g]}] Some practical examples A very simple example of a monad is the lazy Identity monad, which emulates lazy semantics in … Read more