title: Random hex ID in Haskell
body: <p>I am very new to Haskell and hard FP. I have been trying to come up with a function that would generate special type of ID for my project. The ID has 4 groups of 8 digits. The first two groups are always zeros and the other two groups are random 8 digit hex numbers. This is the code I came up with, but it seems to call a lot of things to achieve a simple result. What is the proper Haskell way of doing something like this?</p>
  
  <pre><code>import Data.List (intercalate)
  import System.Random (randomRIO)
  import Numeric (showHex)
  
  deviceId :: IO String
  deviceId = sequence [zeros, zeros, bits, bits] &gt;&gt;= return . intercalate "-"
      where zeros = return "00000000"
            bits = randomRIO (0x10000000::Integer, 0xffffffff::Integer) &gt;&gt;= return . flip showHex ""
  </code></pre>
  
  <p>Edit: thanks to the comments my function now uses fmap and looks like this</p>
  
  <pre><code>deviceId :: IO String
  deviceId = intercalate "-" &lt;$&gt; sequence [zeros, zeros, bits, bits]
      where zeros = return "00000000"
            bits = flip showHex "" &lt;$&gt; randomRIO (0x10000000::Integer, 0xffffffff::Integer)
  </code></pre>
  
  <p>The return on zeros makes sense to me, since it clearly indicates that we are operating on IO strings. Thanks. Any other improvements?</p>