Map.lookupInsertWithDefault ?

Serge D. Mechveliani mechvel at botik.ru
Mon Oct 10 05:39:49 EDT 2005


I am going to use the function

  lookupInsertWithDefault ::
                  Ord a => Map.Map a b -> a -> b -> (Map.Map a b, b)
  lookupInsertWithDefault  tab            a    b' =
    case
        Map.lookup a tab  of  Just b -> (tab,                 b )
                              _      -> (Map.insert a b' tab, b')

Its intention is as in the example:

  lookupInsertWithDefault ftable n (factor n) ->  
                                            (ftable', factorization)

(1) I hope that it will search in the table before trying to compute
    (factor n) by new. Also it stores each new value for future.
(2) I wonder in what relation this may be to existing libraries
    (something like  findWithDefault + insert)
    and whether the Map library may need such.

What the people think of this?

Regards,

-----------------
Serge Mechveliani
mechvel at botik.ru


More information about the Glasgow-haskell-users mailing list