为方便起见,许多关于Parsec别名函数名的Haskell教程。别名在这里可能是错误的技术词,但想法是为函数使用更简单或替代的名称。
使用ghci 8.0.1,以下内容给出错误:
digits = ['one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine']
teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen']
tens = ['twenty', 'thirty', 'fourty', 'fifty',
'sixty', 'seventy', 'eighty', 'ninety']
for word in digits + teens:
print(word)
for tens_word in tens:
print(tens_word) # e.g. twenty
for digits_word in digits:
print(tens_word, digits_word) # e.g. twenty one
print("one hundred")
这是错误:
import Text.ParserCombinators.Parser
run = parseTest
我做错了什么,因为说出以下内容是正确的?
error:
• Ambiguous type variable ‘a0’ arising from a use of ‘parseTest’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
...plus 22 others
...plus 17 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• When instantiating ‘run’, initially inferred to have
this overly-general type:
forall s t a.
(Text.Parsec.Prim.Stream s Data.Functor.Identity.Identity t,
Show a) =>
Text.Parsec.Prim.Parsec s () a -> s -> IO ()
NB: This instantiation can be caused by the monomorphism restriction.
Failed, modules loaded: none.