[Haskell-cafe] Asking for advice on programming style and also performance

Harald Bögeholz bo at ct.de
Mon Sep 3 18:31:16 CEST 2012


Dear Haskell Cafe,


I am working on a solver for Slitherlink puzzles in Haskell. Today I am
completely puzzled that a small change I made had a huge performance
impact. I thought the change to be merely cosmetic to make a function a
little more elegant and the code more readable. But this change slowed
down my program by a factor of 100!

I would greatly appreciate advice from experienced Haskellers why this
has happened. The program is hosted on github; this is the direct link
to the change with unexpected outcome:

https://github.com/ctbo/slitherlink/commit/b6f58699258ef68ddee21a1346bd184465aaaba2

The program itself isn't commented at all, but I have written a sketch
of how it works in the wiki:

https://github.com/ctbo/slitherlink/wiki/How-it-works

While I am at it:

I would also appreciate any advice you might have on the programming
style in general. I am relatively new to Haskell and this is my first
nontrivial program. So any suggestions for improvements are welcome!


Thanks for your time,

-- 
Harald Bögeholz    <bo at ct.de> (PGP key available from servers)
Redaktion c't      Tel.: +49 511 5352-300  Fax: +49 511 5352-417
                   http://www.ct.de/

                   int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;
                   main(){for(;b=c,c-=14;i=printf("%04d",e+d/a),e=d%a)
                   while(g=--b*2)d=h*b+a*(i?f[b]:a/5),h=d/--g,f[b]=d%g;}
                                                          (Arndt/Haenel)

                   Affe Apfel Vergaser

/* Heise Zeitschriften Verlag GmbH & Co. KG * Karl-Wiechert-Allee 10 *
   30625 Hannover * Registergericht: Amtsgericht Hannover HRA 26709 *
   Persönlich haftende Gesellschafterin: Heise Zeitschriften Verlag *
   Geschäftsführung GmbH * Registergericht: Amtsgericht Hannover, HRB
   60405 * Geschäftsführer: Ansgar Heise, Dr. Alfons Schräder */



More information about the Haskell-Cafe mailing list