[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:04:54 UTC 2010


The following commit has been merged in the master branch:
commit 241b72f574c015c281bf426b4646bba3ed2ff41d
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Dec 27 02:36:05 2005 +0100

    Added MissingH.Map
    
    * Added MissingH/Map.hs based on FiniteMap.hs
    * Noted this in MissingH.cabal and README
    * Commented FiniteMap to say it's deprecated

diff --git a/MissingH.cabal b/MissingH.cabal
index 4c9bdf3..3330b7f 100644
--- a/MissingH.cabal
+++ b/MissingH.cabal
@@ -20,7 +20,7 @@ Exposed-Modules: MissingH.Str, MissingH.IO, MissingH.IO.Binary, MissingH.List,
   MissingH.Regex.Pesco,
     MissingH.Str.CSV,
   MissingH.Cmd,
-  MissingH.FiniteMap, MissingH.Path, MissingH.Path.NameManip,
+  MissingH.FiniteMap, MissingH.Map, MissingH.Path, MissingH.Path.NameManip,
     MissingH.Path.FilePath,
   MissingH.Time, MissingH.Time.ParseDate,
   MissingH.Network,
diff --git a/MissingH/FiniteMap.hs b/MissingH/FiniteMap.hs
index bc29676..828a3b9 100644
--- a/MissingH/FiniteMap.hs
+++ b/MissingH/FiniteMap.hs
@@ -28,6 +28,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 This module provides various helpful utilities for dealing with FiniteMaps.
 
+This module is now deprecated in favor of "MissingH.Map" due to the
+similar deprecation in the Haskell standard libraries.
+
 Written by John Goerzen, jgoerzen\@complete.org
 
 In addition to the functions exported, this module also makes a FiniteMap
diff --git a/MissingH/Map.hs b/MissingH/Map.hs
new file mode 100644
index 0000000..3cc5359
--- /dev/null
+++ b/MissingH/Map.hs
@@ -0,0 +1,92 @@
+{- Copyright (C) 2004-2005 John Goerzen <jgoerzen at complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+{- |
+   Module     : MissingH.Map
+   Copyright  : Copyright (C) 2004-2005 John Goerzen
+   License    : GNU GPL, version 2 or above
+
+   Maintainer : John Goerzen <jgoerzen at complete.org> 
+   Stability  : provisional
+   Portability: portable
+
+This module provides various helpful utilities for dealing with Data.Maps.
+
+Written by John Goerzen, jgoerzen\@complete.org
+-}
+
+module MissingH.Map (-- * Basic Utilities
+                     flipM, flippedLookupM, forceLookupM,
+                     -- * Conversions
+                     strToM,
+                     strFromM
+                          )
+where
+
+import qualified Data.Map
+import MissingH.List(flipAL, strToAL, strFromAL)
+
+{- | Converts a String, String Map into a string representation.
+See 'MissingH.List.strFromAL' for more on the similar function for
+association lists.  This implementation is simple:
+
+>strFromM = strFromAL . Data.Map.toList
+
+This function is designed to work with Map String String objects,
+but may also work with other objects with simple representations. -}
+strFromM :: (Show a, Show b, Ord a) => Data.Map.Map a b -> String
+strFromM = strFromAL . Data.Map.toList
+
+{- | Converts a String into a String, String Map.  See
+'MissingH.List.strToAL' for more on the similar function for association
+lists.
+
+This implementation is simple:
+
+>strToM = Data.Map.fromList . strToAL
+
+This function is designed to work with FiniteMap String String objects,
+but may work with other key\/value combinations if they have simple
+representations.  -}
+strToM :: (Read a, Read b, Ord a) => String -> Data.Map.Map a b
+strToM = Data.Map.fromList . strToAL
+
+{- | Flips a Map.  See 'MissingH.List.flipAL' for more on the similar
+function for lists. -}
+
+flipM :: (Ord key, Ord val) => Data.Map.Map key val -> Data.Map.Map val [key]
+flipM = Data.Map.fromList . flipAL . Data.Map.toList
+
+{- | Returns a list of all keys in the Map whose value matches the
+parameter. If the value does not occur in the Map, the empty
+list is returned. -}
+
+flippedLookupM :: (Ord val, Ord key) => Data.Map.Map key val -> val-> [key]
+flippedLookupM fm v =
+    case Data.Map.lookup v (flipM fm) of
+                             Nothing -> []
+                             Just x -> x
+
+{- | Performs a lookup, and raises an exception (with an error message
+prepended with the given string) if the key could not be found.
+-}
+forceLookupM :: (Show key, Ord key) => String -> 
+                                       Data.Map.Map key elt -> key -> elt
+forceLookupM msg fm k =
+    case Data.Map.lookup k fm of
+         Just x -> x
+         Nothing -> error $ msg ++ ": could not find key " ++ (show k)
diff --git a/README b/README
index 973f24a..b81762d 100644
--- a/README
+++ b/README
@@ -137,6 +137,8 @@ MissingH.Logging.         * Logging to local or remote syslog
 MissingH.Logging.Logger   * Primary user interface to logging
                           * Documentation for the logging system
 
+MissingH.Map              * Flip a finite Map and other utilities
+
 MissingH.Maybe            * forceMaybe utility function
 
 MissingH.MIMETypes        * Determine the MIME type of a file
diff --git a/testsrc/Tests.hs b/testsrc/Tests.hs
index d434074..ae3cef7 100644
--- a/testsrc/Tests.hs
+++ b/testsrc/Tests.hs
@@ -21,6 +21,7 @@ import Test.HUnit
 import qualified MIMETypestest
 import qualified Listtest
 import qualified FiniteMaptest
+import qualified Maptest
 import qualified AnyDBMtest
 import qualified Pathtest
 import qualified Strtest
@@ -47,6 +48,7 @@ tests = TestList [TestLabel "test1" test1,
                  TestLabel "CSV" Str.CSVtest.tests,
                  TestLabel "Time" Timetest.tests,
                  TestLabel "FiniteMap" FiniteMaptest.tests,
+                 TestLabel "Map" Maptest.tests,
                  TestLabel "AnyDBM" AnyDBMtest.tests,
                  TestLabel "Path" Pathtest.tests,
                  TestLabel "HVIO" HVIOtest.tests,

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list