as I had been looking for ways to optimize a password cracker I had been making, I came across a much shorter implementation of all possible character combinations in a list, which used this function:
mapM (const xs) [1..n]
where xs
could be the characters available, and n
the length of the desired words.
so
mapM (const "abcd") [1..4]
would output a list ["aaaa","aaab","aaac","aaad","aaba","aabb"..]
and so on. Only the length matters for the list of th right, I could have written ['f','h','s','e']
or any 4 element list instead.
I can see why the list doesn't matter, it's passed to a const
function. I can see that const
of a list technically satisfies (a -> m a)
.
But my question is: why isn't the output simply ["abcd","abcd","abcd","abcd"]
, or maybe "abcdabcdabcdabcd"
? What does a const
function do to output all 4 letter variations for the given letters?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…