From 00fabad1f4aab2778f500372c86e0b295c3d1c54 Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 21 Nov 2015 16:15:34 +0600 Subject: [PATCH] =?UTF-8?q?Add=20type-safe=20synonyms=20of=20=E2=80=98toFi?= =?UTF-8?q?lePath=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps to “double check” programmers' assumptions about what kind of path he is converting into ‘FilePath’. Without these synonyms it's possible to silently convert wrong type of path into ‘FilePath’. --- src/Path.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Path.hs b/src/Path.hs index 9a7b76c..191e915 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -31,6 +31,10 @@ module Path ,dirname -- * Conversion ,toFilePath + ,fromAbsDir + ,fromRelDir + ,fromAbsFile + ,fromRelFile ) where @@ -203,6 +207,22 @@ mkRelFile s = toFilePath :: Path b t -> FilePath toFilePath (Path l) = l +-- | Convert absolute path to directory to 'FilePath' type. +fromAbsDir :: Path Abs Dir -> FilePath +fromAbsDir = toFilePath + +-- | Convert relative path to directory to 'FilePath' type. +fromRelDir :: Path Rel Dir -> FilePath +fromRelDir = toFilePath + +-- | Convert absolute path to file to 'FilePath' type. +fromAbsFile :: Path Abs File -> FilePath +fromAbsFile = toFilePath + +-- | Convert relative path to file to 'FilePath' type. +fromRelFile :: Path Rel File -> FilePath +fromRelFile = toFilePath + -------------------------------------------------------------------------------- -- Operations