The following file is the minimal one I could construct that reproduces your problem. (In the future, you should create such a file yourself for us.)
import Text.Parsec.Prim
data Token
type TokenParser a = Parsec [Token] () a
mytoken :: (Token -> Bool) -> TokenParser Token
mytoken test = token showTok posFromTok testTok
showTok = undefined
posFromTok = undefined
testTok = undefined
Changing the import from Text.Parsec.Prim
to Text.Parsec
fixes the error. (The appropriate instance is defined in Text.Parsec.String
, which is imported by Text.Parsec.Prim
.) You also ask why this change makes it compile but not work:
mytoken :: Stream [Token] Identity Token => (Token -> Bool) -> TokenParser Token
The general rule is that the type "C => T" says: "you can use this thing as if it were a T, provided you can show that constraint C is satisfied". So giving mytoken
the type you did says to wait until mytoken
is used as if it were a plain old (Token -> Bool) -> TokenParser Token
, and as soon as it is, try to discharge the obligation of showing that Stream [Token] Identity Token
holds. Since you still haven't imported the appropriate instance, it can't discharge that obligation and complains.