How to convert list to string?

I make a function which read file and removes in every line all the words that were encountered earlier in the same line.

{-# OPTIONS_GHC -Wall #-}
module Main where
import System.Environment
import System.IO()

main :: IO ()
main = do args <- getArgs 
          if (length args > 0) then do
            f <- get args
            putStrLn (seqWord $ head f)
          else do
            f <- getContents
            putStrLn (seqWord f)

get :: [String] -> IO[String]
get [] = return []
get (file:xs) = do
  contents <- readFile file
  fs <- get xs
  return (contents:fs)

seqWord :: String -> String
seqWord s = show (map (filterWord . words) (lines s))

filterWord :: [String] -> [String]
filterWord [] = []
filterWord (x:xs) = x : filterWord (filter(/=x) xs)

In answer I have list of lists, like this

[["1","12","5","8","13","145","85"],["546","822","1","12","58","8","9"]]

Please, help me fix this problem. Thank you

Upvotes: 0

Views: 2314

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 120079

Use the unwords function to undo the effect of words. You may also want to replace show with unlines.

seqWord s = unlines (map (unwords . filterWord . words) (lines s))

Upvotes: 1

Related Questions