次のコードは、「あいまいな型変数」エラーで失敗します (下)。ただし、レコードを 2 回更新する別の定義は問題なく機能します。これはなぜでしょうか? さらに、以下の「壊れた」定義は、 Trifecta ソースのものと非常によく似ています。私はtrifecta 1.5.2とパーサー0.12.3に対してGHC 7.10.3でコンパイルしています。
module Main where
import Text.Trifecta
import Text.Parser.Token.Style as T
-- This definition causes a type error
identStyle :: TokenParsing m => IdentifierStyle m
identStyle =
T.emptyIdents
{ _styleStart = letter
, _styleLetter = letter
}
これが作業(代替)定義です
identStyle :: TokenParsing m => IdentifierStyle m
identStyle = T.emptyIdents { _styleStart = letter } { _styleLetter = letter }
最初の定義によって生成されるエラーは次のとおりです。
Main.hs:10:3:
Could not deduce (TokenParsing t0)
arising from a use of ‘emptyIdents’
from the context (TokenParsing m)
bound by the type signature for
identStyle :: TokenParsing m => IdentifierStyle m
at Main.hs:8:15-49
The type variable ‘t0’ is ambiguous
Note: there are several potential instances:
instance attoparsec-0.13.0.1:Data.Attoparsec.Internal.Types.Chunk
t =>
TokenParsing
(attoparsec-0.13.0.1:Data.Attoparsec.Internal.Types.Parser t)
-- Defined in ‘Text.Parser.Token’
instance TokenParsing Text.ParserCombinators.ReadP.ReadP
-- Defined in ‘Text.Parser.Token’
instance TokenParsing m => TokenParsing (Unhighlighted m)
-- Defined in ‘Text.Parser.Token’
...plus 11 others
In the expression: emptyIdents
In the expression:
emptyIdents {_styleStart = letter, _styleLetter = letter}
In an equation for ‘identStyle’:
identStyle
= emptyIdents {_styleStart = letter, _styleLetter = letter}
Failed, modules loaded: none.