Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the constraints package work?

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?
like image 781
Roman Cheplyaka Avatar asked Oct 04 '12 13:10

Roman Cheplyaka


1 Answers

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.

like image 97
Edward Kmett Avatar answered Oct 24 '22 17:10

Edward Kmett