title: Haskell: list/vector/array performance tuning
body: <p>I am trying out Haskell to compute partition functions of models in statistical physics. This involves traversing quite large lists of configurations and summing various observables - which I would like to do as efficiently as possible.</p>
  
  <p>The current version of my code is here: <a href="https://gist.github.com/2420539">https://gist.github.com/2420539</a></p>
  
  <p>Some strange things happen when trying to choose between lists and vectors to enumerate the configurations; in particular, to truncate the list, using <code>V.toList . V.take (3^n) . V.fromList</code> (where <code>V</code> is <code>Data.Vector</code>) is faster than just using <code>take</code>, which feels a bit counter-intuitive. In both cases the list is evaluated lazily.</p>
  
  <p>The list itself is built using <code>iterate</code>; if instead I use <code>Vector</code>s as much as possible and build the list by using <code>V.iterateN</code>, again it becomes slower ...</p>
  
  <p>My question is, is there a way (other than splicing <code>V.toList</code> and <code>V.fromList</code> at random places in the code) to predict which one will be the quickest? (BTW, I compile everything using <code>ghc -O2</code> with the current stable version.)</p>