Trivial parsec example produces a type error

瘦欲@ 提交于 2019-12-04 23:03:55
fuz

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:

  1. Give simple an explicit signature:

    simple :: Stream s m Char => ParsecT s u m Char
    simple = letter
    
  2. Disable the monorphism restriction:

    {-# LANGUAGE NoMonomorphismRestriction #-}
    import Text.Parsec
    simple = letter
    

See What is the monomorphism restriction? for more information on the monomorphism restriction.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!