Answer the question
In order to leave comments, you need to log in
How to make beautiful inference in Haskell?
Hello. I'm doing a Haskell assignment. Here is the code
{-# OPTIONS_GHC -Wall #-}
module Main where
import System.IO()
import System.Environment
main :: IO ()
main = do args <- getArgs
if (length args > 0) then do
f <- readFile $ head args
putStrLn $ seqWord f
else do
f <- getContents
putStrLn $ seqWord f
seqWord :: String -> String
seqWord [] = []
seqWord s = show $ unlines (map (unwords . filterWord . words) (lines s))
filterWord :: [String] -> [String]
filterWord [] = []
filterWord (x:xs) = x : filterWord (filter(/=x) xs)
seqWord s = show $ unlines (map (unwords . filterWord . words) (lines s))
"\"111111 1 11\"\n\"5555 5 55\"\n"
seqWord s = unlines (map (unwords . filterWord . words) (lines s))
1 12 5 8 13 145 85
546 822 1 12 58 8 9
444 4 44
Answer the question
In order to leave comments, you need to log in
Show does not output, it only converts one value to another. PutStrLn and comrades are involved in the output. They require [Char] or String as input. If you already have a [Char] value, then you don't need to `show` it.
If you have a list of strings on hand, then you need to look at what the actual task is. If the lines need to be displayed one after another, without hyphens, then they can be glued together using `unwords`. The resulting string can be immediately shipped to `putStrLn`. If you need to display several lines one after another, then you can either glue them together through `unlines` and output them in one `putStrLn`, or call putStrln on each line from the list separately.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question