small fixes patch

John Meacham john at repetae.net
Wed Jan 26 05:30:33 EST 2005


attached is a patch to fix a module name and generalise a couple
functions in Data.Map to be usable in an arbitrary monad (rather than
being restricted to Maybe). if someone could integrate it, that would be
great.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 
-------------- next part --------------
? base/System/u
? monads/dirs
? monads/utils/renameObjs
Index: base/Data/FunctorM.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/FunctorM.hs,v
retrieving revision 1.1
diff -u -r1.1 FunctorM.hs
--- base/Data/FunctorM.hs	17 Jan 2005 11:08:52 -0000	1.1
+++ base/Data/FunctorM.hs	26 Jan 2005 10:24:18 -0000
@@ -12,7 +12,7 @@
 --
 -----------------------------------------------------------------------------
 
-module FunctorM (
+module Data.FunctorM (
 	FunctorM(..)
   ) where
 
Index: base/Data/Map.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/Map.hs,v
retrieving revision 1.9
diff -u -r1.9 Map.hs
--- base/Data/Map.hs	21 Jan 2005 11:44:09 -0000	1.9
+++ base/Data/Map.hs	26 Jan 2005 10:24:21 -0000
@@ -225,14 +225,18 @@
 
 
 -- | /O(log n)/. Lookup the value at a key in the map.
-lookup :: Ord k => k -> Map k a -> Maybe a
-lookup k t
+lookup :: (Monad m,Ord k) => k -> Map k a -> m a
+lookup k t = case lookup' k t of
+    Just x -> return x
+    Nothing -> fail "Data.Map.lookup: Key not found"
+lookup' :: Ord k => k -> Map k a -> Maybe a
+lookup' k t
   = case t of
       Tip -> Nothing
       Bin sz kx x l r
           -> case compare k kx of
-               LT -> lookup k l
-               GT -> lookup k r
+               LT -> lookup' k l
+               GT -> lookup' k r
                EQ -> Just x       
 
 -- | /O(log n)/. Is the key a member of the map?
@@ -395,9 +399,10 @@
 
 -- | /O(log n)/. Lookup the /index/ of a key. The index is a number from
 -- /0/ up to, but not including, the 'size' of the map. 
-lookupIndex :: Ord k => k -> Map k a -> Maybe Int
-lookupIndex k t
-  = lookup 0 t
+lookupIndex :: (Monad m,Ord k) => k -> Map k a -> m Int
+lookupIndex k t = case lookup 0 t of
+    Nothing -> fail "Data.Map.lookupIndex: Key not found."
+    Just x -> return x
   where
     lookup idx Tip  = Nothing
     lookup idx (Bin _ kx x l r)


More information about the Libraries mailing list