[Haskell-beginners] Flying Dutchman sailing blind

Bas van Dijk v.dijk.bas at gmail.com
Wed Oct 6 03:18:14 EDT 2010


On Tue, Oct 5, 2010 at 1:46 PM, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> On 5 October 2010 09:06, Jeroen van Maanen <jeroen at lexau.org> wrote:
>
>>
>> P.S. For an idea of what is living in the snail pit, have a look at:
>>
>>  http://lexau.svn.sourceforge.net/viewvc/lexau/branches/totem/src/LExAu/Pipeline/Concurrent.hs?view=markup
>>  http://lexau.svn.sourceforge.net/viewvc/lexau/branches/totem/src/LExAu/Model/HistoryTree.hs?view=markup
>>
>> (I know, HistoryTree.hs badly needs to be split up into smaller modules.)
>
> A minor style tip...
>
> You are using ShowS family functions (showString, showChar) to
> generate strings which is good as it avoids (++). However, to make the
> code clearer you might want to code up a little helper library with
> ShowS versions of the usual pretty print combinators.
>
> e.g. all the functions like parens:
>
> parens :: ShowS -> ShowS
> parens s = showChar '(' . s . showChar ')'
>
>
> Having a library of these functions usually pays off (I think there is
> one on Hackage but I can't remember its name). You could use a pretty
> printing library, but they are somewhat less efficient as the have to
> do work measuring line lengths for fitting lines to screen width.
>
> Best wishes
>
> Stephen
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>

Instead of a ShowS you might want to use a DString[1] which is
basically a newtype wrapper around a ShowS. The advantage of a DString
is that it has an instance for IsString which allows you to write
overloaded string literals of type DString.

You might also take a look at string-combinators[2] which provides
handy polymorphic functions to build and combine string-like values.
For example it provides:

paren :: (Monoid s, IsString s) => s -> s

(I've no idea why I named this 'paren' instead of 'parens' I will
change this in the next version)

Regards,

Bas

[1] http://hackage.haskell.org/package/dstring
[2] http://hackage.haskell.org/package/string-combinators


More information about the Beginners mailing list