Haskell load external txt file into list -


hello following code wordfeud program. allows search through list of words matching prefix, suffix, , letters. question is, instead of using list @ bottom, want use external text file containing words , load list. how go doing this?

count :: string -> string -> int count _[] = 0 count [] _ = 0 count (x:xs) square     |x `elem` square = 1 + count xs (delete x square)     |otherwise = count xs square  check :: string -> string -> string -> string -> bool check prefix suffix word square     | (length strippedword) == (count strippedword square) = true     | otherwise = false             strippedword = drop (length prefix) (take ((length word ) - (length suffix)) word)   wordfeud :: string -> string -> string -> [string] wordfeud b c = test1         test =["horse","chair","chairman","bag","house","mouse","dirt","sport"]      test1 = [x| x <- test, `isprefixof` x, b `issuffixof` x, check b x c] 

very simple, of lines function (or words, when words seperated other form of whitespace line breaks):

-- loads words text file list. getwords :: filepath -> io [string] getwords path = contents <- readfile path                    return (lines contents) 

furthermore, you'll have read on io in haskell (i recommend googling 'io haskell tutorial'), if haven't done already. you'll need introduce interactivity program.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -