Printing a field with additional dots in haskell
- by Frank Kluyt
I'm writing a function called printField. This function takes an int and a string as arguments and then then prints a field like this "Derp..." with this: printField 7 "Derp". When the field consists of digits the output should be "...3456".
The function I wrote looks like this:
printField :: Int -> String -> String
printField x y = if isDigit y
then concat(replicate n ".") ++ y
else y ++ concat(replicate n ".")
where n = x - length y
This obviously isn't working. The error I get from GHC is:
Couldn't match type `[Char]' with `Char'
Expected type: Char
Actual type: String
In the first argument of `isDigit', namely `y'
In the expression: isDigit y
In the expression:
if isDigit y then
concat (replicate n ".") ++ y
else
y ++ concat (replicate n ".")
I can't get it to work :(. Can anyone help me out? Please keep in mind that I'm new to Haskell and functional programming in general.