Convert all the elements in a file into a array in haskell -
I have a file that has a set of 200,000 words and I want to read the program data and store it in array. And make a new array with all 200,000 words.
I import the code
system.IO main = do handle and lt; - Openfile is written as "words.txt" but giving error as type error on line 5
"ReadModa content & lt; - hGetContentsCon & lt; - Rows content putStrLn (show con) hClose handle
and the text file is a form
ABRIDGMENT ABRIDGMENTS ABRIIN ABRIN ABRINS ABRIS and so on
What is the amendment
def readFile (): allwords = [] for the word in open < Code> ("Words.txt"): allwords.append (word.strip ()) return all words
can be
readFile "words.txt" & gt; & Gt; = Return type
:: IO [string] or you can write getWordsFromFile :: string - & gt; IO [string] getWordsFromFile file = read file file & gt; = = Return and
use as word = "word.txt" getStrLn $ "file is included" ++ (Length word list) ++ "word." Very constructive comments from @Sanityinc and @Sarah (thanks!): @Sanityinc: "Other option: fmap word $ readFile file by & lt; $ & gt; control.profit " or word & lt; $ & Gt; ReadFile file / Em> @ Sarah: "When you see foo>> = return bar bar It can be changed with fmap bar foo because you are not actually using additional forces that come with monad and in most cases without any complex type There is more true in the future, where applicable monad " A super word of / html> Is c
Comments
Post a Comment