A program I am writing in Haskell has a list instance of my defined type:
type Locals = [(String, Float)]
I am trying to update this list by receiving a String and updating the corresponding float value, but the String might not be in the list at the time.
Since Haskell lists are immutable, I decided the easiest way was to do this (in pseudocode):
if a tuple containing the string exists:
delete it
add the correct data
I want to know:
a) If there is an easier way to do this
b) If not, how would I go about deleting the correct element
Thanks
That looks like an associative map. I would use Data.Map
. This is known as a "dictionary" in other languages. Map.insert
does what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With