Commits

Bryan O'Sullivan committed 4c2fa06 Merge

Merge pull request #30 from sol/use-equational-constraints

Use equational constraints for IsString instances

Comments (0)

Files changed (3)

Data/Attoparsec/ByteString/Char8.hs

-{-# LANGUAGE BangPatterns, FlexibleInstances, TypeSynonymInstances #-}
+{-# LANGUAGE BangPatterns, FlexibleInstances, TypeSynonymInstances, GADTs #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 
 -- |
 import qualified Data.ByteString as B8
 import qualified Data.ByteString.Char8 as B
 
-instance IsString (Parser B.ByteString) where
+instance (a ~ B.ByteString) => IsString (Parser a) where
     fromString = I.string . B.pack
 
 -- $encodings

Data/Attoparsec/Text/Internal.hs

 {-# LANGUAGE BangPatterns, CPP, FlexibleInstances, OverloadedStrings,
-    Rank2Types, RecordWildCards, TypeSynonymInstances #-}
+    Rank2Types, RecordWildCards, TypeSynonymInstances, GADTs #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 -- |
 -- Module      :  Data.Attoparsec.Text.Internal
 type Failure r = T.Failure Text r
 type Success a r = T.Success Text a r
 
-instance IsString (Parser Text) where
+instance (a ~ Text) => IsString (Parser a) where
     fromString = string . T.pack
 
 lengthAtLeast :: T.Text -> Int -> Bool

examples/RFC2616.hs

     } deriving (Eq, Ord, Show)
 
 httpVersion :: Parser B.ByteString
-httpVersion = string "HTTP/" *> P.takeWhile (\c -> isDigit_w8 c || c == 46)
+httpVersion = "HTTP/" *> P.takeWhile (\c -> isDigit_w8 c || c == 46)
 
 requestLine :: Parser Request
 requestLine = do