I am using the following code in Haskell to get an output of letter combinations.
combinations pre suf letters = prefixed ++ suffixed
where
perms = permutation letters
prefixed = map (\x -> pre ++ x) $ perms
suffixed = map (\x -> x ++ suf) $ perms
I want to import a large textfile like dictonary.txt as a list ["Apple", "Banana.....]" with the structure of:
Apple
Banana
Stawberry
...... and so on
This imported [String] I want to merge with the output [String] of combinations. Somebody who can help me with this?
edit: To make it more clear. The combinations function gives a output like:
["banana","nanaba,..."]
<- All posible combinations of a couple of characters.
I want to merge this list with a list with a list that is created from a txt file (but I dont know ho to import a txt to a list of strings and use it to merge). So the output will be like.
["banana","nanaba,...,Apple,Banana,Strawbery"]
After that it will print the double words in the string.
Another edit with Ankurs code:
combinations pre suf letters = prefixed ++ suffixed
where
perms = permutation letters
prefixed = map (\x -> pre ++ x) $ perms
suffixed = map (\x -> x ++ suf) $ perms
fileLines :: FilePath -> IO [String]
fileLines file = readFile file >>= (\x -> return $ lines x)
main = do
lines <- fileLines "directory.txt"
putStr $ (combinations pre suf letters) ++ lines
I will get a parser error on this one! :22:22: parse error on input `='
Can someone help me how to order this code? So it dont get anny errors?
main
, that must be non-indented. – Daniel Fischercombinations
, you must provide the actual arguments. Something likeputStr . unlines $ combinations "prefix" "suffix" "banana" ++ lines
. – Daniel Fischer