Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One easy suggestion is to use <code>hlint</code> which is a program that checks your source code and makes suggestions for improvements syntax wise. This might not increase speed because most likely it's already done by the compiler or the lazy evaluation. But it <em>might</em> help the compiler in some cases. Further more it will make you a better Haskell programmer since you will learn better ways to do things, and it might be easier to understand your program and analyze it.</p> <p>examples taken from <a href="http://community.haskell.org/~ndm/darcs/hlint/hlint.htm">http://community.haskell.org/~ndm/darcs/hlint/hlint.htm</a> such as:</p> <pre><code>darcs-2.1.2\src\CommandLine.lhs:94:1: Error: Use concatMap Found: concat $ map escapeC s Why not: concatMap escapeC s </code></pre> <p>and </p> <pre><code>darcs-2.1.2\src\Darcs\Patch\Test.lhs:306:1: Error: Use a more efficient monadic variant Found: mapM (delete_line (fn2fp f) line) old Why not: mapM_ (delete_line (fn2fp f) line) old </code></pre> <p>I think the largest increases you can do in Project Euler problems is to understand the problem and remove unnecessary computations. Even if you don't understand everything you can do some small fixes which will make your program run twice the speed. Let's say you are looking for primes up to 1.000.000, then you of course can do <code>filter isPrime [1..1000000]</code>. But if you think a bit, then you can realize that well, no even number above is a prime, there you have removed (about) half the work. Instead doing <code>[1,2] ++ filter isPrime [3,5..999999]</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload