[commit: ghc] wip/nfs-locking: Implement encodeModule -- the inverse for decodeModule. (ba41ded)
git at git.haskell.org
git at git.haskell.org
Fri Oct 27 00:14:54 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/nfs-locking
Link : http://ghc.haskell.org/trac/ghc/changeset/ba41dedc0c632836dff3c3ce55f7210d344e44e7/ghc
>---------------------------------------------------------------
commit ba41dedc0c632836dff3c3ce55f7210d344e44e7
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date: Wed Dec 23 06:12:19 2015 +0000
Implement encodeModule -- the inverse for decodeModule.
>---------------------------------------------------------------
ba41dedc0c632836dff3c3ce55f7210d344e44e7
src/Base.hs | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/Base.hs b/src/Base.hs
index ac457ad..79ce119 100644
--- a/src/Base.hs
+++ b/src/Base.hs
@@ -25,9 +25,8 @@ module Base (
module System.Console.ANSI,
-- * Miscellaneous utilities
- bimap, minusOrd, intersectOrd,
- removeFileIfExists,
- replaceEq, replaceSeparators, decodeModule, unifyPath, (-/-), chunksOfSize,
+ bimap, minusOrd, intersectOrd, removeFileIfExists, replaceEq, chunksOfSize,
+ replaceSeparators, decodeModule, encodeModule, unifyPath, (-/-)
) where
import Control.Applicative
@@ -78,12 +77,18 @@ replaceSeparators = replaceIf isPathSeparator
replaceIf :: (a -> Bool) -> a -> [a] -> [a]
replaceIf p to = map (\from -> if p from then to else from)
--- | Given a module name extract the directory and file names, e.g.:
+-- | Given a module name extract the directory and file name, e.g.:
--
-- > decodeModule "Data.Functor.Identity" = ("Data/Functor/", "Identity")
decodeModule :: String -> (FilePath, String)
decodeModule = splitFileName . replaceEq '.' '/'
+-- | Given the directory and file name find the corresponding module name, e.g.:
+--
+-- > encodeModule "Data/Functor/" "Identity.hs" = "Data.Functor.Identity"
+encodeModule :: FilePath -> String -> String
+encodeModule dir file = replaceEq '/' '.' $ dir -/- takeBaseName file
+
-- | Normalise a path and convert all path separators to @/@, even on Windows.
unifyPath :: FilePath -> FilePath
unifyPath = toStandard . normaliseEx
More information about the ghc-commits
mailing list