lookupFM vs Prelude.lookup

Alastair Reid reid@cs.utah.edu
Tue, 8 May 2001 15:17:50 -0600 (MDT)


This is somewhat well known but I just got caught by it yet again so
I'd like to add it to the list of things that need fixed in hslibs.

Prelude.lookup and lookupFM _almost_ have the same type:

  Prelude.lookup :: <context> => a      -> [(a,b)] -> Maybe b
  lookupFM       :: <context> => FM a b -> a       -> Maybe b

Close enough that your mind treats them the same, different enough
that Haskell won't.

It'd be much better if these took their arguments in the same order.
That is, either:

  Prelude.lookup :: <context> => [(a,b)] -> a -> Maybe b
  lookupFM       :: <context> => FM a b  -> a -> Maybe b

or:

  Prelude.lookup :: <context> => a -> [(a,b)] -> Maybe b
  lookupFM       :: <context> => a -> FM a b  -> Maybe b

Despite being on the library committee at the time, I don't understand
why H98 went for the argument order it did (I prefer the FiniteMap
order) but, since it's the standard, I propose that they get swapped
in FiniteMap when things get reorganised.

(I know this will be very painful for people who use FMs heavily
(e.g., GHC) but it's easier to make these changes relatively early.)

-- 
Alastair Reid        reid@cs.utah.edu        http://www.cs.utah.edu/~reid/

ps Since FM provides, essentially, the same functionality as Arrays,
it really ought to have a much more similar interface.  I'll leave off
the details for now (just apply s/FiniteMap/Array/ to the types of FM
functions and check them off against the Array interface).

pps Is there a list of things to be done to hslibs?  It'd be good to
have a place in a CVS tree somewhere where we could add things or to
have John Hughes' Standard Haskell web page software
(http://www.cs.chalmers.se/~rjmh/Haskell/Messages/Display.cgi?id=0) or
something.  The current mail archive isn't as good because it doesn't
have enough structure and there's no place you can go to to find what
is currently agreed on, what is still open to discussion and what is
being ignored.  (The same goes for the ffi list.)