title: How lazy is Haskell's `++`?
body: <p>I'm curious how I should go about improving the performance of a Haskell routine that finds the lexicographically minimal cyclic rotation of a string.</p>
  
  <pre><code>import Data.List
  swapAt n = f . splitAt n where f (a,b) = b++a
  minimumrotation x = minimum $ map (\i -&gt; swapAt i x) $ elemIndices (minimum x) x
  </code></pre>
  
  <p>I'd imagine that I should use Data.Vector rather than lists because Data.Vector provides in-place operations, probably just manipulating some indices into the original data.  I shouldn't actually need to bother tracking the indices myself to avoid excess copying, right?</p>
  
  <p>I'm curious how the <code>++</code> impact the optimization though.  I'd imagine it produces a lazy string thunk that never does the appending until the string gets read that far.  Ergo, the <code>a</code> should never actually be appended onto the <code>b</code> whenever minimum can eliminate that string early, like because it begins with some very later letter.  Is this correct?</p>