使语言实用程序重叠工作时出现问题

时间:2019-04-08 16:33:09

标签: haskell ghc

我无法使用以下实例:

newtype ParseState a = ParseState {
  state :: a
} deriving (Show)

newtype Parse m a b = Parse { -- In monad m, parsing from state a to b
  runParse :: ParseState a -> m (b,ParseState a)
}

instance Monad m => Monad (Parse m a) where
  parser >>= f = Parse $ \s -> do
    (result,s') <- runParse parser s
    runParse (f result) s'

instance {-# OVERLAPPING #-} (Monad m, Show a) => Monad (Parse m a) where
  (>>=) = -- same definition as above
  fail err = Parse $ \s ->
    fail $ "Parsing error while at" ++ (show s) ++ " : " ++ err

GHC给我错误“重复实例声明”。 Section 7.6.3.4 of GHC manual似乎允许这种构造,不是吗?

如果没有,我该如何解决?

0 个答案:

没有答案