Haskell: Replacing element with a given key in an association list -
I need to create a function that is given as a key (in the form of a string , A value (in the form of a string ) and a union list of keys and values ( [(string, string)] ). The meaning of the function is to add the key / value pair at the end of the list, and, if the key is already in the list with the associated value, remove the old value.
I have tried to use the lookup on the key and affiliation list, but I'm not sure what to do with the output - the output type of the lookup < / Code> function is maybe string , and I can not seem to act on it (like leaving elements), by any means I can see through the list and Any list element attached to a given key I delete without the Uly?
You should write a recursive function that will insert the new key / value-pair and the current list as a parameter , And write through the list to make a new list with loops added to the new value. For each list element, you check that the key is similar to what you want to insert. If it is different then you keep that old element, if it is the same then you add new items instead of the old one. If you reach the end of the list without finding the key, then you finally add a new item here.
Comments
Post a Comment