简体   繁体   English

Haskell:警告“变量是否因上下文而被隐式量化”是什么意思?

[英]Haskell: What does the warning “Variable is implicitly quantified due to a context” mean?

At this line 在这一行

type SafeReturn a = Exception e => Either e a

I got this warning 我收到了这个警告

Variable ‘e’ is implicitly quantified due to a context
Use explicit forall syntax instead.

What does it mean? 这是什么意思?

You have a free type variable in your type synonym which you haven't dealt with. 您的类型同义词中有一个自由类型变量,您尚未处理。 To take the extreme example, if we removed your a parameter, we'd have something like 举一个极端的例子,如果我们删除了你a参数,我们会有类似的东西

type SafeReturn = [e] -- Using a * -> * type instead of a * -> * -> * type

This probably isn't what you want since we don't know know exactly what e is referring to here and this is the same problem that your SafeReturn faces; 这可能不是你想要的,因为我们不知道e在这里指的是什么,这与你的SafeReturn面临的问题相同; what does the e mean? 什么是e是什么意思?

Now there is one context where e could mean something and that's what the error message is telling you. 现在有一个上下文,其中e可能意味着什么,这就是错误消息告诉你的内容。

type SafeReturn a = forall e. Exception e => Either e a

This means something different. 这意味着不同的东西。 In fact you've created a universally quantified type here. 事实上,你已经在这里创建了一个普遍量化的类型。 This means that anything of type SafeReturn a has no way of inspecting e other than whatever methods are offered by Exception . 这意味着除了Exception提供的任何方法之外, SafeReturn a类型的任何东西都无法检查e

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM