这是一个错误吗?
{-# LANGUAGE NoMonomorphismRestriction #-}
import qualified Text.Parsec.Token as P
import Text.Parsec.Language (haskellDef)
(P.TokenParser { P.identifier = ident }) = P.makeTokenParser haskellDef
Run Code Online (Sandbox Code Playgroud)
ident类型的收益率Text.Parsec.Prim.ParsecT String GHC.Prim.Any Data.Functor.Identity.Identity String,而定义
haskell = P.makeTokenParser haskellDef
ident = P.identifier haskell
Run Code Online (Sandbox Code Playgroud)
产生一种类型 Text.Parsec.Prim.ParsecT String u Data.Functor.Identity.Identity String
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))
Run Code Online (Sandbox Code Playgroud)
然后,尝试运行它,
*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}}"
Run Code Online (Sandbox Code Playgroud)
并不是的; 我相信它符合报告的行为:模式中的完全多态类型变量被实例化Any.但是,在GHC 7.2之后,这可以像您期望的那样工作(尤其是最后的提交消息).
至于GHCi行为,这是因为GHCi的扩展默认规则默认为完全多态变量().