[英]What language extensions does the MTL library require?
I'm trying to understand monad transformers by implementing my own tiny library based on the designs of existing ones. 我试图通过基于现有设计实现我自己的小型库来理解monad变换器。
What I'm stuck on is the language extensions. 我坚持的是语言扩展。 In MonadError , the only extension mentioned is
UndecidableInstances
. 在MonadError中 ,提到的唯一扩展是
UndecidableInstances
。 However, I can't get similar code to compile without also using FunctionalDependencies
and FlexibleInstances
. 但是,如果不使用
FunctionalDependencies
和FlexibleInstances
,我无法获得类似的代码。
Example that I believe requires FunDeps: 我认为需要FunDeps的例子:
class (Monad m) => MonadError e m | m -> e where
And a flexible instance: 一个灵活的实例:
instance MonadError e m => MonadError e (MaybeT m) where
How does the MonadError
code avoid the extra two extensions? MonadError
代码如何避免额外的两个扩展?
You don't have to spell out all the extensions in the source file itself. 您不必拼写源文件本身的所有扩展名。 Common extensions that are used by all/most modules can be listed in the project's cabal file.
所有/大多数模块使用的公共扩展可以列在项目的cabal文件中。 In mtl's case :
在mtl的情况下 :
extensions:
MultiParamTypeClasses
FunctionalDependencies
FlexibleInstances
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.