Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in unification #16

Closed
fehrenbach opened this issue Nov 17, 2014 · 3 comments
Closed

Possible bug in unification #16

fehrenbach opened this issue Nov 17, 2014 · 3 comments

Comments

@fehrenbach
Copy link
Member

I get this somewhat confusing error message.
Is this a bug in the unification code, or could someone explain to me what's wrong with my code?

Unification error: Rows
 |_
and
 |_
 could not be unified because one is closed and the other has a rigid row variable
Unification error: Couldn't match ((id:Int,parent:Int,schema:Int,value:String|_)) -> Bool against ((id:Int,parent:Int,schema:Int,value:String|_)) {}-@ _::Any
/home/stefan/src/dbwiki/xpath.links:287: Type error: The function
    `filter'
has type
    `((id:Int,parent:Int,schema:Int,value:String|_)) -> Bool'
while the arguments passed to it have types
    `(id:Int,parent:Int,schema:Int,value:String|_)'
and the currently allowed effects are
    `'.
In expression: filter(r).
@fehrenbach
Copy link
Member Author

As small as an example as I can manage:

var db = database "stefan";

var exists = compose(not, empty);

typename Data = (parent : Int, value  : String);

typename CompilationContext = TableHandle(Data,Data,Data);

sig filterConstraint : (CompilationContext) ~> (Data) -> Bool
fun filterConstraint (data) {
  var aa = fun (x) {
             for (text <-- data)
             where ( true )
               [(val = text.value)]
             };
  fun (x) {
    exists(
      for (a <- aa(x))
      where (a.val == "b")
        [()]
    )
  }
}

var data = table ("ciawfb_data") with Data from db;
var filter = filterConstraint(data);
query {
  for (r <-- data)
  where (filter(r))
    [r]
}

Replacing sig filterConstraint : (CompilationContext) ~> (Data) -> Bool by sig filterConstraint : (CompilationContext) ~> (Data) {}-> Bool "fixes" the problem.

@slindley
Copy link
Contributor

Here's a smaller example:

var exists = compose(not, empty);

sig filterConstraint : () -> Bool
fun filterConstraint () {
  exists([()])
}

query {
  [(x=filterConstraint())]
}

There is a bug in Links in the way it is reporting the bug in your program. The bug in your program is that due to the ML value restriction, exists is not polymorphic in its effects, but filterConstraint is declared to have a type that is polymorphic in its effects. The solution is to eta expand exists:

fun exists(xs) {not(empty(xs))}

or:

var exists = fun (xs) {compose(not, empty)(xs)};

In fact, we could, and perhaps should relax the value restriction in the case of pure functions (like compose, pure, and empty), in which case your original program would work.

@fehrenbach
Copy link
Member Author

Thanks, I fixed my code :-)
Now I'll have to do some reading on the value restriction.

slindley added a commit that referenced this issue Nov 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants