Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating tuple elements of a list in Haskell

Tags:

list

haskell

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

like image 999
TartanLlama Avatar asked Dec 04 '10 21:12

TartanLlama


1 Answers

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.

like image 107
luqui Avatar answered Oct 06 '22 10:10

luqui