title: Exchanging multiple pairs of characters in a Haskell string
body: <p>I'm trying to write a Haskell function that takes a string of pairs of letters, and exchanges the letters of the pair in a string of all letters, but what I've come up with feels awkward and unidiomatic.</p>
  
  <p>I have</p>
  
  <pre><code>swap a b = map (\x-&gt; if x == a then b else if x == b then a else x)
  sub n = foldr (.) id (zipWith swap (head &lt;$&gt; splitOn "." n) (last &lt;$&gt; splitOn "." n)) ['A'..'Z']
  </code></pre>
  
  <p>which works well enough giving</p>
  
  <pre><code>&gt; sub "RB.XD.EU.ZM.IJ"
  "ARCXUFGHJIKLZNOPQBSTEVWDYM"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&gt; sub "YC.LU.EB.TZ.RB.XD.IJ"
  "ARYXBFGHJIKUMNOPQESZLVWDCT"
  </code></pre>
  
  <p>but I'm new to Haskell and feel like my approach — especially my <code>swap</code> helper function (which I only use here) — is more elaborate than it needs to be.</p>
  
  <p>Is there a better, more idiomatic, approach to this problem; especially one that takes advantage of a language feature, builtin, or library function that I've missed?</p>