How does the constraints package work?

随声附和 提交于 2020-01-01 08:18:12

问题


The idea behind Data.Constraint.Forall, as I understand it, is to use coercion in the implementation, but ensure safety using the type system. I have two questions regarding the latter.

  1. Why do we need two skolem variables — A and B? I would imagine that if a constraint is satisfied by an «unknown» type, then it is polymorphic. How does the second type give more safety?
  2. Why are these types called skolem variables? I thought that skolemnization is used to remove existential quantification, and here we see universal quantification. Is there a sign-flipping somewhere which I missed?

回答1:


It is possible with an MPTC and functional dependency to identify the Skolem when it is a single variable, by using a constraint parameterized on a constraint. The trick I used to do that doesn't work when there are two.

From the perspective of code written outside of this module, the variables are Skolemized. They are effectively a 'fresh' type constructor.

But given that you can't refer explicitly to these types outside of the module since they aren't exported, any instance that covers these Skolems has to be universally quantified.

This is how I upgrade from an existential to a universal. The 'sign flip' comes from their unexported nature, not technically from their role as Skolems.



来源:https://stackoverflow.com/questions/12728159/how-does-the-constraints-package-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!