Permalink
Browse files

Added FilePath newtype to represent texts with slashes in them

  • Loading branch information...
1 parent eacc4d4 commit 0cc9e65cba5ca4b6af05c1eb53ca27819a91de78 @tomlokhorst committed Jul 10, 2011
Showing with 18 additions and 1 deletion.
  1. +18 −1 Web/Zwaluw.hs
View
19 Web/Zwaluw.hs
@@ -27,9 +27,12 @@ module Web.Zwaluw (
, rLeft, rRight, rEither
, rNothing, rJust, rMaybe
, rTrue, rFalse
+
+ -- * FilePath data type and router
+ , FilePath, filePath
) where
-import Prelude hiding ((.), id, (/))
+import Prelude hiding ((.), id, (/), FilePath)
import Control.Monad (guard)
import Control.Category
import Data.Monoid
@@ -193,3 +196,17 @@ rMaybe r = rJust . r <> rNothing
$(deriveRouters ''Bool)
rTrue :: Router r (Bool :- r)
rFalse :: Router r (Bool :- r)
+
+-- | Represents a file path, including slashes
+newtype FilePath = FilePath { unFilePath :: T.Text }
+
+instance Show FilePath where
+ showsPrec p (FilePath t) r = showsPrec p t r
+
+filePath :: Router r (FilePath :- r)
+filePath = val parse' serialize
+ where
+ parse' "" = []
+ parse' s = [(FilePath . T.pack $ s, "")]
+ serialize = return . (++) . T.unpack . unFilePath
+

0 comments on commit 0cc9e65

Please sign in to comment.