[Haskell-cafe] Re: breaking too long lines

Christian Maeder Christian.Maeder at dfki.de
Wed Apr 22 05:29:35 EDT 2009


Maurí­cio wrote:
>> according the several style guides, lines shouldn't be too long
>> (longer than 78 characters).
> 
> Since Haskell is usually nice to parse, wouldn't it be
> interesting to replace a pretty printer program for layout
> manuals? I saw in your first link that the teacher provided
> a tool to check for non-compliant layout, but wouldn't it
> be easier to provide a pretty-printer (with line size as one
> parameter to the command line)?

Yes, this tool
http://www.cs.caltech.edu/courses/cs11/material/haskell/misc/haskell_style_check
is quite good. It should have been written in Haskell!

(Btw, it warns wrongly about a comma not followed by a space in a
character literal ',')

My other favorite tool is hlint
http://community.haskell.org/~ndm/darcs/hlint/hlint.htm

Surely, I would prefer a single tool. There are certainly some style
elements that can be corrected automatically, like replacing tabs,
deleting trailing whitespace, putting a final newline at the of a file,
shrinking more than 2 consecutive blank lines to just two blank lines, etc.

However, parsing and pretty-printing code _and_ all comments (!) is not
that easy to implement. Also tools like Haddock and programatica have
limitations (and are written for different purposes).

Some comments may refer to line numbers! (This is quite common in
teaching documents and maybe correctly and better achieved by labels.)

A conversion program could support different style options, but it would
need to make sure that the resulting text is still valid haskell and
produces "equivalent" code. But also a speed-up may mess-up your overall
behavior!

Looking at hlint, it makes suggestions that require additional imports
or use different function. All these may cause ambiguities, although
unlikely. Some suggestions (eta-reduce) cause the monomorphism-
restriction to jump in.

The current pretty-printer happened to put a lambda sign "\" as the last
character on a line causing "cpp" to fail, etc.

Yet, such a (difficult to implement) tool would be useful.

Cheers Christian


More information about the Haskell-Cafe mailing list