Permalink
Browse files

Removed redundant ConvertAttempt instances from String

  • Loading branch information...
1 parent 38f8b91 commit adae391e6efdcd4fd93c973cce0d32043e2e8808 @snoyberg committed Dec 7, 2009
Showing with 6 additions and 43 deletions.
  1. +2 −41 Data/Convertible/Instances/String.hs
  2. +4 −2 utils/StringHelper.hs
@@ -56,8 +56,6 @@ instance Exception InvalidDayException
instance ConvertSuccess Day [Char] where
convertSuccess = show
-instance ConvertAttempt Day [Char] where
- convertAttempt = return . convertSuccess
instance ConvertAttempt [Char] Day where
convertAttempt s = wrapFailure (const $ InvalidDayException s) $ do
SF.assert (length s == 10) () $ InvalidDayException s
@@ -71,8 +69,6 @@ data InvalidBoolException = InvalidBoolException String
deriving (Show, Typeable)
instance Exception InvalidBoolException
-instance ConvertAttempt Bool [Char] where
- convertAttempt = return . convertSuccess
instance ConvertSuccess Bool [Char] where
convertSuccess b = if b then "true" else "false"
instance ConvertAttempt [Char] Bool where
@@ -108,20 +104,17 @@ instance ConvertAttempt [Char] Bool where
-- Int
instance ConvertSuccess Int [Char] where
convertSuccess = show
-instance ConvertAttempt Int [Char] where
- convertAttempt = return . convertSuccess
instance ConvertAttempt [Char] Int where
convertAttempt = SF.read
-- Rational
instance ConvertSuccess (Ratio Integer) [Char] where
convertSuccess = show
-instance ConvertAttempt (Ratio Integer) [Char] where
- convertAttempt = return . convertSuccess
instance ConvertAttempt [Char] (Ratio Integer) where
convertAttempt = SF.read
--- Instances for bytestrings and text
+-- Instances for bytestrings and text (generated by utils/StringHelper.hs)
+
instance ConvertAttempt BS.ByteString Day where
convertAttempt = fromStringA <=< convertAttempt
instance ConvertAttempt BL.ByteString Day where
@@ -154,38 +147,6 @@ instance ConvertAttempt ST.Text (Ratio Integer) where
convertAttempt = fromStringA <=< convertAttempt
instance ConvertAttempt LT.Text (Ratio Integer) where
convertAttempt = fromStringA <=< convertAttempt
-instance ConvertAttempt Day BS.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Day BL.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Day ST.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Day LT.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Bool BS.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Bool BL.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Bool ST.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Bool LT.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Int BS.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Int BL.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Int ST.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt Int LT.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt (Ratio Integer) BS.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt (Ratio Integer) BL.ByteString where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt (Ratio Integer) ST.Text where
- convertAttempt = convertAttempt . toString
-instance ConvertAttempt (Ratio Integer) LT.Text where
- convertAttempt = convertAttempt . toString
instance ConvertSuccess Day BS.ByteString where
convertSuccess = convertSuccess . toString
instance ConvertSuccess Day BL.ByteString where
@@ -1,13 +1,15 @@
+import Control.Monad
+
types = ["BS.ByteString", "BL.ByteString", "ST.Text", "LT.Text"]
fromStringAttempts = ["Day", "Bool", "Int", "(Ratio Integer)"]
fromStringSuccesses = []
toStringAttempts = []
toStringSuccesses = ["Day", "Bool", "Int", "(Ratio Integer)"]
main = do
- mapM_ fsa $ fromStringAttempts ++ fromStringSuccesses
+ mapM_ fsa fromStringAttempts
mapM_ fss fromStringSuccesses
- mapM_ tsa $ toStringAttempts ++ toStringSuccesses
+ mapM_ tsa toStringAttempts
mapM_ tss toStringSuccesses
fsa t = forM_ types (\f -> putStrLn $

0 comments on commit adae391

Please sign in to comment.