Typically for text processing, Text is used and not Strings, since Text works with an array of unboxed unicode characters. One can justify with justifyLeft :: Int -> Char -> Text -> Text and justifyRight :: Int -> Char -> Text -> Text. For example:
{-# LANGUAGE OverloadedStrings #-}
import Data.Text(Text, justifyLeft, justifyRight)
import Data.Text.IO as TI
myText :: Text
myText = "Hello stackoverflow."
main :: IO ()
main = do
TI.putStrLn (justifyLeft 40 ' ' myText)
TI.putStrLn (justifyRight 40 ' ' myText)
The ' ' is here the character used as "fill character". For example if we use justifyLeft 40 '#' myText and justifyRight 40 '#' myText instead, we get:
Hello stackoverflow.####################
####################Hello stackoverflow.
StringandText!putStrLntakesStringbut decent alignment module exist only which takesText.prettyprinterorboxeslibraries are a better choice.