[Haskell-cafe] Re: request for code review
benjamin.franksen at bessy.de
Wed Mar 15 03:56:34 EST 2006
On Tuesday 14 March 2006 20:58, you wrote:
> On 3/14/06, Benjamin Franksen <benjamin.franksen at bessy.de> wrote:
> > On Tuesday 14 March 2006 14:46, Pete Chown wrote:
> > > Shannon -jj Behrens wrote:
> > > > Arrows looks like a replacement for monads. Are you saying
> > > > I should drop my use of the State monad? If so, why? I like
> > > > the readability of the do syntax.
> > >
> > > Okay, now it's my turn to ask a question. :-) I've read about
> > > arrows, and while I think I see what they do, I'm not sure why
> > > they are seen as so special that they even get new syntax. This
> > > question of Shannon's is exactly the point I struggle with. I
> > > can see that the arrow operators might be useful with functions,
> > > but are they useful for other things too?
> > Yes, http://www.haskell.org/arrows/biblio.html lists a number of
> > papers describing non-trivial applications of Arrows, that is,
> > Arrows other than (->). I found the exposition in
> > http://www.haskell.org/yale/papers/oxford02/ to be quite readable.
> > > For example, as monads are one kind of arrow,
> > > I thought I would make some of the I/O functions into arrows and
> > > see what happened. The result was pretty much the same as using
> > > the monad, except slightly less convenient.
> > You can write monadic code without ever using the syntax sugar, and
> > get along. However, do-notation is convenient. OTOH, I am told that
> > programming with Arrows is really quite inconvenient w/o the syntax
> > sugar.
> Well, forgive me for my newbie-ness:
> o How important is it that I switch from using the State monad to
> using arrows?
I can see no good reason to do it.
> o How important is it that I switch from using |> or $
> to using arrows?
Not important. Arrows are just another way to structure a program.
However, they have been designed for cases where a monad can /not/ be
applied, such as e.g. self-optimizing parser combinators.
> (It seems that using arrows just to replace |> or $
> is like using a sledge hammer to drive a thumb tack.)
> o How much will this increase the "conceptual complexity" of my
> program--i.e. how much time am I going to have to spend explaining it
> in my article?
A lot, so I'd say leave it alone. I would use either plain function
application or --perhaps-- a state monad.
> o How much will this improve the readability or decrease the amount
> of code in my program?
See above. I don't think you gain anything by using (>>>). However, I
still recommend using function application ($) instead of inverse
application (|>) because this closer to idiomatic Haskell.
Besides, readability depends on how proficient the reader is. People who
regularly program using Arrows may find it easy to read. I don't and
have more difficulty understanding it than e.g. monadic code.
More information about the Haskell-Cafe