-- Implementation of a mapping, a set of (key,value) pairs. -- Sergio Antoy -- Tue Jul 17 08:32:17 PDT 2001 -- The store is a list of pairs where the first element is the -- key and the second is the mapped value. -- The representation is a list. If an ordering were available for -- the keys, a more efficient tree representation would be possible. -- The initial store is an empty mapping. -- Getting a mapping fails if and only if the key is not in the store. -- Consider instead returning a default value, e.g., 0. -- The value of a key is obtained by instantiating an argument of the call. -- Setting a mapping either adds a (key,value) pair to the store -- or updates the value of a key already in the store. -- Setting a mapping always returns a new mapping. init_store = [] get a b ((x,y):z) | a == x = b =:= y | otherwise = get a b z set a b [] = [(a,b)] set a b ((x,y):z) | a == x = (x,b) : z | otherwise = (x,y) : set a b z