gpt4 book ai didi

haskell - 新类型派生 Monad 错误

转载 作者:行者123 更新时间:2023-12-04 16:09:48 27 4
gpt4 key购买 nike

我正在尝试安装应用程序 Termite - Util但是我在第 14 行遇到了这个错误

newtype CE m a = CE {unCE :: m a} deriving (Monad)

错误说:

ContextError.hs:14:45: No instance for (Applicative (CE m)) arising from the 'deriving' clause of a data type declaration Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself When deriving the instance for (Monad (CE m))

我已经尝试过 CIS 194: Homework 7 中提出的解决方案

添加这个:

instance Applicative (CE m) where pure = return (<*>) = ap

但是我又报错了

ContextError.hs:14:45: No instance for (Functor (CE m)) arising from the 'deriving' clause of a data type declaration Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself When deriving the instance for (Monad (CE m))

我真的不知道如何继续,我是 Haskell 的新手

提前致谢。

最佳答案

在 ghc 7.10.1 中,AMP 提议发生了。在此之前,您可以在没有 Applicative 实例的情况下定义 Monad 实例,在 7.10.1 之后,您必须定义 FunctorApplicative 如果你想定义一个 Monad

https://wiki.haskell.org/Functor-Applicative-Monad_Proposal

关于haskell - 新类型派生 Monad 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44647521/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com