I have made these functions:
-- Looks up in dict and returns Maybe key
myLookUp :: [(String, [String])] -> String -> String
myLookUp [] val = []
myLookUp ((k, vs):ds) val
| val `elem` snd (myLast ds) = myCensor val
| val `elem` vs = k
| otherwise = myLookUp ds val
-- Given a dict of tuples of strings and list of strings,
-- should return the last tuple in dict
myLast :: [(String, [String])] -> (String, [String])
myLast [] = error "Empty list"
myLast [x] = x
myLast (x:xs) = myLast xs
Which compiles, but when I try to test it I get an error saying
ghci> myLookUp [("strength", ["ignorance"]), ("bla", ["blabla", "blabla"])] "aa"
*** Exception: Empty list
CallStack (from HasCallStack):
error, called at test.hs:103:13 in main:Main
And if I try to remove my base case myLast [] = error "Empty list" I get this error:
myLookUp [("strength", ["ignorance"]), ("bla", ["blabla", "blabla"])] "aa"
*** Exception: test.hs:(104,1)-(105,25):
Non-exhaustive patterns in function myLast
I think that myLast works because I get this output:
myLast [("strength", ["ignorance"]), ("bla", ["blabla", "blabla"])]
("bla",["blabla","blabla"])
And I thought I could use snd on the tuple to get the list-element, but since I get this error, I'm uncertain as to what I am doing wrong.