So, I have this function which aims to align the text on the left without cutting words(only white spaces). However my problem is that I cannot find a stopping condition of the function and it goes infinitely.
f n "" = "" --weak condition f n s = if n >= ((maximum . map length . words) s) then if (s !! n == ' ' || s !! n == '\t' || s !! n == '\n') then take n s ++ "\n" ++ (f n ( drop n s)) else f (n-1) s else error "Try bigger width!"
Well, basically if the n is smaller than the longest word then it prompts error, else it ''cuts'' the string in the white spaces until it reaches a not white space character, then it calls itself recursively for
n-1. I use also
putStr to avoid "\n" in the output.
However, as I already said the stopping condition is too weak or non-existent. If there are other flows in the code or possible optimizations(e.g. less ifs), please tell.