I’m trying to get this trivial parsec code to compile
import Text.Parsec
simple = letter
but I keep getting this error
No instance for (Stream s0 m0 Char)
arising from a use of `letter'
Possible fix: add an instance declaration for (Stream s0 m0 Char)
In the expression: letter
In an equation for `simple': simple = letter
I think you have ran against the monomorphism restriction. This restriction means: If a variable is declared with no explicit arguments, its type has to be monomorphic. This forces the typechecker to pick a particular instance of
Stream, but it can’t decide.There are two ways to fight it:
Give
simplean explicit signature:Disable the monorphism restriction:
See What is the monomorphism restriction? for more information on the monomorphism restriction.