- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有类型
ActionT TL.Text (ReaderT T.Text IO)
我正在尝试为此创建一个 MonadReader 实例,这样我就不必提出询问,但总是得到
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use -XFlexibleInstances if you want to disable this)
我尝试了很多实例类型,下面是一些实例类型,但它们总是出现上述错误
instance MonadReader T.Text (ActionT TL.Text (ReaderT T.Text IO))
instance MonadReader r (ActionT TL.Text (ReaderT r IO))
instance (ScottyError e, MonadReader r m) => MonadReader r (ActionT e (ReaderT r m))
我觉得我错过了实例的一些基本内容。我想我明白了FlexibleInstances
但我看不出这在这里如何适用。
任何有关实例类型的帮助将不胜感激,我想实现 ask
和local
我自己的主要目标是学习。
谢谢。
我让它与 FlexibleInstances, MultiParamTypeClasses, UndecidableInstances
一起工作和
instance (ScottyError e, Monad m, MonadReader r m) => MonadReader r (ActionT e m) where
ask = lift ask
仍在致力于本地化的实现。我还假设 UndecidableInstances
不好吗?
我认为我真正需要的是。
instance (ScottyError e, Monad m, MonadReader r m) => MonadReader r (ActionT e (ReaderT r m)) where
但我还是想不通local
最佳答案
正如您自己回答的那样,您需要 UndecidableInstances
来实现完全通用的 MonadReader
实例。这是一个必要的罪恶,你可以在所有实现此类通用 monad 类型类实例的库中看到它。
恐怕实现local
会是一个问题。如果你看the standard instances ,它们都使用某种特定于特定 monad 的映射函数。而且由于 ActiveT
似乎都没有导出这样的方法或其内部结构,因此它看起来不可行。
关于haskell - Scotty 的 ActionT 的 MonadReader 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23147892/
我有类型 ActionT TL.Text (ReaderT T.Text IO) 我正在尝试为此创建一个 MonadReader 实例,这样我就不必提出询问,但总是得到 (All instance
我是一名优秀的程序员,十分优秀!