In my homework, I want to write a function which adds a string to a list of strings, but I have no idea how to do it.
I thought it would be something like this:
AddToLS :: [String] -> String -> [String]
AddToLS ls s = (ls : s)
But this code doesn't even compile.
It should work like this:
AddToLS [] "one" =["one"]
AddToLS ["one"] "two" =["one","two"]
AddToLS ["one","two"] "there" =["one","two","there"]
(x:list). This is because the Haskell runtime system maintains only a pointer to the beginning of the list. Remember, lists can be unlimited, so in general you cannot maintain a pointer to the end of the list.