-- -- print-ihtfp.hs -- -- Build with: -- ghc --make print-ihtfp -- Run with: -- ./print-ihtfp -- -- Or, in ghci: -- :l print-ihtfp -- main -- import Data.Char (toUpper) distribute :: a -> [a] -> [[a]] distribute x [] = [[x]] distribute x (y:ys) = (x:y:ys) : (map (y:) $ distribute x ys) permute :: [a] -> [[a]] permute [] = [] permute [x] = [[x]] permute (x:xs) = concatMap (distribute x) (permute xs) permuteSentence :: String -> [String] permuteSentence x = map unwords $ permute $ words x nums :: [String] nums = map (++ ": ") $ map show [1..] fixSentence :: String -> String fixSentence "" = "" fixSentence (x:xs) = (toUpper x) : xs ++ "!" ihtfp :: [String] ihtfp = permuteSentence "I hate this fucking place" main = do putStrLn $ unlines $ zipWith (++) nums $ map fixSentence ihtfp