Is this a bug?
{-# LANGUAGE NoMonomorphismRestriction #-}
import qualified Text.Parsec.Token as P
import Text.Parsec.Language (haskellDef)
(P.TokenParser { P.identifier = ident }) = P.makeTokenParser haskellDef
yields ident of type Text.Parsec.Prim.ParsecT String GHC.Prim.Any Data.Functor.Identity.Identity String, whereas defining
haskell = P.makeTokenParser haskellDef
ident = P.identifier haskell
yields one of type Text.Parsec.Prim.ParsecT String u Data.Functor.Identity.Identity String
The behavior is not identical in ghci,
infixl 4 <++>
(<++>) = liftM2 (++)
(P.TokenParser { P.identifier = ident }) = P.makeTokenParser haskellDef
suitable_macro = ident
parseMacro = many space *> suitable_macro
parseMacro' =
try (string "{{" *> parseMacro <* string "}}")
parseAll = many (noneOf "{") <++>
option "" (parseMacro' <|> (string "{" <++> parseAll))
Then, try to run it,
*Hz2.Preproc> parseTest parseAll "asdf{{b}}"
<interactive>:0:11:
Couldn't match expected type `()' with actual type `GHC.Prim.Any'
Expected type: Parsec String () a0
Actual type: ParsecT
String GHC.Prim.Any Data.Functor.Identity.Identity [Char]
In the first argument of `parseTest', namely `parseAll'
In the expression: parseTest parseAll "asdf{{b}}"
Not really; I believe it's Report-compliant behaviour: fully polymorphic type variables in patterns are instantiated to Any. However, in GHC 7.2 onwards, this works like you'd expect (see especially the commit message at the end).
As for the GHCi behaviour, this is because GHCi's extended defaulting rules default fully-polymorphic variables to ().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With