I wish to construct a random string consisting of only alphabetical characters. This is the code I have so far:
letters :: String
letters = "abcdefghijklmnopqrstuvwxyz"
{- | Generates any lower case alpha character.
-}
lowerAlpha :: Gen Char
lowerAlpha = oneof (map return letters)
getString :: Int -> String
getString 0 = []
getString n = lowerAlpha : getString (n - 1)
getString is passed a random Int between 1 and 25. Because lowerAlpha returns a Gen Char getString wont work as it expects a Char in order to build a String. Is there a way to change a Gen String to a String? This is the line of code where the problem occurs - getString n = lowerAlpha : getString (n - 1)
Genandoneofare.Charis an instance ofEnum, you can writeletters = ['a'..'z']to avoid having to type out all the lowercase letters by hand.oneOfhere. It will surely be faster to usechoose ('a', 'z').