-
Notifications
You must be signed in to change notification settings - Fork 219
unify Combine and CombineTypes #2651
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
b66de13
e07a39e
068d623
bb59a38
f7c03e3
d21abae
be4ea39
11a7b3c
8050d24
8fe9623
e7b55f0
20dfebd
5933b6a
79d0da8
189d572
0bcc84d
0ecadb1
400549e
43a8741
5f51a3f
7a5bca8
7864ec9
d7b782c
53a5a3d
df0330c
aa6fd30
c942a3d
87845fa
9557e57
5cfc83c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,15 +801,24 @@ | |
Combine _ mk l r -> do | ||
_L' <- loop ctx l | ||
|
||
let l'' = quote names (eval values l) | ||
let l' = eval values l | ||
|
||
let l'' = quote names l' | ||
|
||
_R' <- loop ctx r | ||
|
||
let r'' = quote names (eval values r) | ||
let r' = eval values r | ||
|
||
xLs' <- case _L' of | ||
VRecord xLs' -> | ||
return xLs' | ||
let r'' = quote names r' | ||
|
||
-- The `Combine` operator should now work on record terms and also on record types. | ||
-- If both sides are record terms, we set leftTypeOrRecord and rightTypeOrRecord to (Left record_fields). | ||
-- If both sides are record types, we set both of them to (Right (Type, record_fields)). | ||
-- Then we match the pair (leftTypeOrRecord, rightTypeOrRecord) to make sure we catch errors. | ||
leftTypeOrRecord <- case (_L', l') of | ||
(VRecord xLs', _) -> return (Left xLs') | ||
|
||
(VConst cL, VRecord xLs') -> return (Right (cL, xLs')) | ||
|
||
_ -> do | ||
let _L'' = quote names _L' | ||
|
@@ -818,9 +827,12 @@ | |
Nothing -> die (MustCombineARecord '∧' l'' _L'') | ||
Just t -> die (InvalidDuplicateField t l _L'') | ||
|
||
xRs' <- case _R' of | ||
VRecord xRs' -> | ||
return xRs' | ||
-- Make sure both are on the Left (both record values) or on the Right (both record types). | ||
rightTypeOrRecord <- case (leftTypeOrRecord, _R', r') of | ||
(Left _, VRecord xRs', _) -> | ||
return (Left xRs') | ||
|
||
(Right _, VConst cR, VRecord xRs') -> return (Right (cR, xRs')) | ||
|
||
_ -> do | ||
let _R'' = quote names _R' | ||
|
@@ -845,7 +857,26 @@ | |
|
||
return (VRecord xTs) | ||
|
||
combineTypes [] xLs' xRs' | ||
let combineTypesCheck xs xLs₀' xRs₀' = do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can pull this out of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
let combine x (VRecord xLs₁') (VRecord xRs₁') = | ||
combineTypesCheck (x : xs) xLs₁' xRs₁' | ||
|
||
combine x _ _ = | ||
die (FieldTypeCollision (NonEmpty.reverse (x :| xs))) | ||
|
||
let mL = Dhall.Map.toMap xLs₀' | ||
let mR = Dhall.Map.toMap xRs₀' | ||
|
||
Foldable.sequence_ (Data.Map.intersectionWithKey combine mL mR) | ||
|
||
case (leftTypeOrRecord, rightTypeOrRecord) of | ||
Check warning on line 872 in dhall/src/Dhall/TypeCheck.hs
|
||
(Left xLs', Left xRs') -> do | ||
combineTypes [] xLs' xRs' | ||
(Right (cL, xLs'), Right (cR, xRs')) -> do | ||
let c = max cL cR | ||
combineTypesCheck [] xLs' xRs' | ||
return (VConst c) | ||
|
||
|
||
CombineTypes _ l r -> do | ||
_L' <- loop ctx l | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to first construct
leftTypeOrRecord
, thenrightTypeOfRecord
, and do the check that they are bothLeft
or bothRight
afterwards in a separate step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand your comment. It appears to me that my code already does what you say: it first constructs
leftTypeOrRecord
, thenrightTypeOfRecord
, and then checks that they are both Left or both Right in a separate expression.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that you match on
leftTypeOrRecord
when you constructrightTypeOrRecord
.I think something like the following results in better error messages: