git.iko.soy/typeable/attoparsec
on master help sign in
Use equational constraints for IsString instances

This helps with type checking. Here is an example: "foo" *> "bar" :: Parser Text This code did not type check before, because we had an `IsString` instance for `Parser Text`, but all that the type checker can infer about "foo" is that it is of type `Parser a`. The instance I added is now for `Parser a` instead, but we also constrain the type of `a` to `Text`. With this the above code does now type check: If the type checker sees `Parser a` it selects the right instance, and by extension will infer `a` to be of type `Text`.

commit0265427d09d64e3292cb77cfecca4679ef60ccc3 authorSimon Hengel <sol@typeful.net> dateSun 18 Nov 2012, 09:05 (14 years ago) parentf6f9a46
2 files changed+4−4
Data/Attoparsec/ByteString/Char8.hs+2−2 Data/Attoparsec/Text/Internal.hs+2−2
Data/Attoparsec/ByteString/Char8.hs+2−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, FlexibleInstances, TypeSynonymInstances #-}
1+{-# LANGUAGE BangPatterns, FlexibleInstances, TypeSynonymInstances, GADTs #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33
44-- |
@@ -123,7 +123,7 @@ import qualified Data.Attoparsec.Internal as I
123123import qualified Data.ByteString as B8
124124import qualified Data.ByteString.Char8 as B
125125
126−instance IsString (Parser B.ByteString) where
126+instance (a ~ B.ByteString) => IsString (Parser a) where
127127 fromString = I.string . B.pack
128128
129129-- $encodings
Data/Attoparsec/Text/Internal.hs+2−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE BangPatterns, CPP, FlexibleInstances, OverloadedStrings,
2− Rank2Types, RecordWildCards, TypeSynonymInstances #-}
2+ Rank2Types, RecordWildCards, TypeSynonymInstances, GADTs #-}
33{-# OPTIONS_GHC -fno-warn-orphans #-}
44-- |
55-- Module : Data.Attoparsec.Text.Internal
@@ -92,7 +92,7 @@ type Added = T.Added Text
9292type Failure r = T.Failure Text r
9393type Success a r = T.Success Text a r
9494
95−instance IsString (Parser Text) where
95+instance (a ~ Text) => IsString (Parser a) where
9696 fromString = string . T.pack
9797
9898lengthAtLeast :: T.Text -> Int -> Bool