[Haskell-beginners] Multidimensional Matrices in Haskell

Dave Bayer bayer at cpw.math.columbia.edu
Wed Jul 7 10:56:47 EDT 2010


On Jul 7, 2010, at 7:08 AM, Mihai Maruseac wrote:

> I'm interested in both immutable and mutable ones but I don't want them to be trapped inside a monad of any kind.

If you want mutable data, you've imposing some serious constraints on the sequence in which your program can be evaluated. Like death and taxes, you cannot escape this. Monads are one way to handle this. If you want "plug and play" they're probably the easiest way to handle this, for any other approach you're going to have to get very involved in designing an alternative for yourself.

By "trapped" do you mean that you don't want to write your whole program inside "do" notation? By analogy, there are some sequence constraints in any program, and some people would rather express as much of their program as possible using function composition, rather than naming variables and passing arguments. This is called "point-free" and if you like this, the pragmatic sweet spot is to strive for it some but not all of the time.

By analogy, some of us find monads easiest to understand via Kleisli composition, which is rather obvious, and we are baffled by the axioms used to present monads in Haskell, which leave no impression whatsoever no matter how many times one reads them.

At a pragmatic level, monads simply bury some plumbing under the street for you. Very convenient. If you find yourself still writing everything using "do" notation, it's because not everything was buried under the street for you. Specialize the monad further to your setting, with a goal of expressing as much as possible as Kleisli composition, introduce an infix composition operator for this, and most of your code should end up composition, not "do" notation. This is akin to striving for a point-free style in ordinary code.

I found this to be the case, writing parsers to transform text. Parsing is a classic application of monads, but I was baffled why everyone thought the parsers inside "do" notation where so pretty. I felt "trapped" as you fear feeling. But because my return type was invariably ShowS, it was very easy to write nearly everything as composition, regaining the clean feeling I remember e.g. from similar code in Bigloo Scheme.




More information about the Beginners mailing list