1
votes

How can I create list of String in Haskell in order to use it in a function which takes the list and a word as arguments and looks for the same Char from a word in the list of String? Should I use Data.Map or Data.List for creating a list? I've tried creating it like this:

dictionary :: [String]
dictonary = fromList ["wit","ass","bad","shoe","cold","pie","and","or"]
1
Remove fromList and you are done. The brackets already form a list, there's no need to do anything else.chi
Well if you want a list of strings, I do not see why you need a fromList. You already constructed a list.Willem Van Onsem

1 Answers

1
votes

Perhaps something like

import Data.List
let checkIfContains :: [String] -> String -> Integer
checkIfContains x y = elemIndex y x

Then an example of running this would be:

checkIfContains ["lol", "heh"] "heh"

output: Just 1

So if you input a list of Strings x and a String y to see if y is in x, then the output is the index y in x (as here we found "heh" in index 1 of x). If y is not in x the output should be

Nothing

Thing to note, this function finds the first occurrence of y in x, so if if you have two entries of y in x, then it'll show the index of the first occurrence.