This piece of code actually combines two pretty implicit facts about Haskell:
- That strings are by default lists of characters
- That lists are an implementation of the indeterminism monad, which enumerates all possible paths when combined.
The following code pieces are equivalent:
replicateM n "12"
replicateM n ['1', '2']
replicateM n $ do c <- ['1', '2']
return c
I would argue that the last version actually shows most cleanly what happens in this case: That we have a choice between '1' and '2' and that n of these choices are chained together. Once you understand that, you are as advanced in your Haskell understanding as you need to be. The rest is just a nice bit of obfuscation.