I need to use List Comprehension to generate a list like this one: ["AaBB", "AbBB", "AcBB", "AdBB", "AeBB", "AfBB","AgBB"]. But I've been running into some problems creating a expression to do it
I've tried to create a list which every element would be a string concatenation, something like this "A" + x + "BB" where x is a element from a range of letters starting with "a" and ending with "g"
module C where
genList :: [String]
genList = [ "A" ++ x ++ "BB" | x <- ["a" .. "g"]]
So, I was expecting to generate a list similar to the one asked in the problem. But instead I just got this compiling error:
Prelude> :l exC
[1 of 1] Compiling C ( exC.hs, interpreted )
exC.hs:3:41: error:
• No instance for (Enum [Char])
arising from the arithmetic sequence ‘"a" .. "g"’
• In the expression: ["a" .. "g"]
In a stmt of a list comprehension: x <- ["a" .. "g"]
In the expression: ["A" ++ x ++ "BB" | x <- ["a" .. "g"]]
|
3 | genList = [ "A" ++ x ++ "BB" | x <- ["a" .. "g"]]
| ^^^^^^^^^^^^
Failed, no modules loaded.