Excel column to Int and vice-versa - improvements sought
<p>In the code below, I am happy with the functionality i.e. the code produces the output that I expect. However, comparing the length of <strong>toCol</strong> to <strong>toInt</strong> - I am interested in knowing if you could offer something to trim it (i.e. <strong>toCol</strong> ) down. Many thanks!</p>

<pre><code>-- given a spreadsheet column as a string
-- returns integer giving the position of the column
-- ex:
-- toInt "A" = 1
-- toInt "XFD" = 16384
toInt :: String -&gt; Int
toInt = foldl fn 0
  where
    fn = \a c -&gt; 26*a + ((ord c)-64)

-- given a integer returns
-- the column to be found at that position as a [Char]
-- ex:
-- toCol 1 = "A"
-- toCol 16384 = "XFD"
toCol :: Int -&gt; [Char]
toCol n = toCol' n []
  where
    toCol' 0 a = a
    toCol' n a =
      let r = mod n 26 in
        case (r == 0) of
          True -&gt; toCol' (div (n-1) 26) ('Z':a)
          False -&gt; toCol' (div n 26) (chr(r + 64) : a)
</code></pre>