Skip to content

Fix entailment issues with skolems and matches#3121

Merged
LiamGoodacre merged 1 commit intopurescript:masterfrom
LiamGoodacre:fix/skolem-apart
Oct 21, 2017
Merged

Fix entailment issues with skolems and matches#3121
LiamGoodacre merged 1 commit intopurescript:masterfrom
LiamGoodacre:fix/skolem-apart

Conversation

@LiamGoodacre
Copy link
Copy Markdown
Member

When verifying a substitution, if we see a skolem (that hasn't been
matched with itself) then it is unknown whether or not we might have a
match or be apart.

Combining a match with an unknown should be an unknown not a match.
I.e: knowing that one of two things match doesn't make the other one now
a match.

Added failing examples to catch these cases.

module InstanceChains.BothUnknownAndMatch where

class Same l r o | l r -> o
instance sameY :: Same t t @"Y" else instance sameN :: Same l r @"N"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, well there's the kind error again :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, no, I didn't see the proxy :)

-- for label `m`, `Int ~ Int` should be a match
-- together they should be Unknown
example :: forall t. @t -> @_
example _ = same @(u :: t, m :: Int) @(u :: Int, m :: Int)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is a kind error, surely?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to readers: when this comment was made, same had type forall l r o. Same l r o => @l -> @r -> @o.

pairwiseAll _ [] = True
pairwiseAll _ [_] = True
pairwiseAll p (x : xs) = all (p x) xs && pairwiseAll p xs
pairwiseAll :: (a -> a -> Matched ()) -> [a] -> Matched ()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use any monoid as the result, right?

meet ts | pairwiseAll typesAreEqual ts = Just ts
| otherwise = Nothing
verifySubstitution :: Matching [Type] -> Matched (Matching [Type])
verifySubstitution mts = foldMap meet mts $> mts where
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice :)

Copy link
Copy Markdown
Contributor

@paf31 paf31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from fixing up the future kind error, this looks great to me. Thanks for working on this!

When verifying a substitution, if we see a skolem (that hasn't been
matched with itself) then it is unknown whether or not we might have a
match or be apart.

Combining a match with an unknown should be an unknown not a match.
I.e: knowing that one of two things match doesn't make the other one now
a match.

Added failing examples to catch these cases.
@LiamGoodacre LiamGoodacre merged commit c68befe into purescript:master Oct 21, 2017
@LiamGoodacre LiamGoodacre deleted the fix/skolem-apart branch October 21, 2017 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants