问题描述
newtype JSONWithErr a = JSONWithErr (Writer (Array Foreign.ForeignError) a)
derive newtype instance jsonWithErrApply :: Apply JSONWithErr
derive newtype instance jsonWithErrapplicative :: applicative JSONWithErr
derive newtype instance jsonWithErrFunctor :: Functor JSONWithErr
derive newtype instance jsonWithErrBind :: Bind JSONWithErr
derive newtype instance jsonWithErrMonad :: Monad JSONWithErr
derive newtype instance jsonWithErrTell :: MonadTell (Array Foreign.ForeignError) JSONWithErr
derive newtype instance jsonWithErrWriter :: MonadWriter (Array Foreign.ForeignError) JSONWithErr
newtype JSONParse a = JSONParse (ExceptT (NonEmptyList ForeignError) JSONWithErr a)
derive newtype instance jsonParseApply :: Apply JSONParse
derive newtype instance jsonParseapplicative :: applicative JSONParse
derive newtype instance jsonParseFunctor :: Functor JSONParse
derive newtype instance jsonParseBind :: Bind JSONParse
derive newtype instance jsonParseMonad :: Monad JSONParse
derive newtype instance jsonParseTell :: MonadTell (Array Foreign.ForeignError) JSONParse
derive newtype instance jsonParseWriter :: MonadWriter (Array Foreign.ForeignError) JSONParse
derive newtype instance jsonParseThrow :: MonadThrow (NonEmptyList ForeignError) JSONParse
generalize :: forall m a. Monad m => Identity a -> m a
generalize = unwrap >>> pure
-- type Except e = ExceptT e Identity
genExcept :: forall m e a. Monad m => ExceptT e Identity a -> ExceptT e m a
genExcept = unwrap >>> generalize >>> ExceptT
readJSON' :: forall a. JSON.ReadForeign a => String -> JSONParse a
readJSON' s = JSONParse $ genExcept $ (pure >>> JSONWithErr) <$> (JSON.readJSON' s) -}
这里的错误涵盖了 readJSON'
的整个定义,是:
Could not match type
JSONWithErr t2
with type
a0
while trying to match type JSONParse t1
with type JSONParse a0
while checking that expression (apply JSONParse) ((apply genExcept) ((map (...)) (readJSON' s)))
has type JSONParse a0
in value declaration readJSON'
where a0 is a rigid type variable
bound at (line 0,column 0 - line 0,column 0)
t1 is an unkNown type
t2 is an unkNown type
我试图简化它,但我似乎遇到了约束问题;在下面的简化中,键入的孔由于较早的错误而不起作用:
tmp :: forall a. JSON.ReadForeign a => String -> ExceptT (NonEmptyList ForeignError) JSONWithErr a
tmp s = ?help (JSON.readJSON' s)
和错误:
No type class instance was found for
Simple.JSON.ReadForeign t0
The instance head contains unkNown type variables. Consider adding a type annotation.
while applying a function readJSON'
of type ReadForeign t0 => String -> ExceptT (NonEmptyList ForeignError) Identity t0
to argument s
while inferring the type of readJSON' s
in value declaration tmp
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)