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

Add field for unions #9

Merged
merged 11 commits into from
Nov 10, 2020
Merged

Add field for unions #9

merged 11 commits into from
Nov 10, 2020

Conversation

alexhumphreys
Copy link
Owner

@alexhumphreys alexhumphreys commented Nov 3, 2020

Added the . (field) operator for unions. Depends on #8

Commit 62a30be is an interesting on here. I added VHLam and VHPi for handling fields. I thought I could get away with letting the parser handling union constructor with arguments, but that wouldn't handle the following case:

let x = <Foo : Text>
let y = x.Foo
in y "bar"

So since the apply operator needed to know about field application, and I'd need to synth some complicated types, it seemed easier to add VHLam and VHPi. My thinking is the VH* stuff is for built ins, or things constructed during type synthesis, and VLam and VPi are for actual lambdas found in the user provided dhall expressions. Both VPi and VHPi get read back as EPi, so the should be possible to compare.

@alexhumphreys alexhumphreys force-pushed the feat/union-field branch 6 times, most recently from 6e701f4 to 1ea653e Compare November 5, 2020 10:48
Copy link

@Danten Danten left a comment

Choose a reason for hiding this comment

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

Have mostly skimmed the code, but seems good

Idrall/Check.idr Outdated
Comment on lines 108 to 118
aEquivUnion : (i : Integer) ->
Namespace -> List (FieldName, (Maybe (Expr Void))) ->
Namespace -> List (FieldName, (Maybe (Expr Void))) -> Bool
aEquivUnion i ns1 [] ns2 [] = True
aEquivUnion i ns1 ((k, Nothing) :: xs) ns2 ((k', Nothing) :: ys) =
k == k' && aEquivUnion i ns1 xs ns2 ys
aEquivUnion i ns1 ((k, Just v) :: xs) ns2 ((k', Just v') :: ys) =
k == k' &&
aEquivHelper i ns1 v ns2 v' &&
aEquivUnion i ns1 xs ns2 ys
aEquivUnion i ns1 _ ns2 _ = False
Copy link

Choose a reason for hiding this comment

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

Hmm, so I'm not sure how dhall works, but we might have to be more careful here. Is <Foo: Int, Bar: String> the same type as <Bar: String, Foo: Int>. Some languages with these kind of types allow the order to be different, but still be "same" type.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's a SortedMap and keys should be unique (the check for which i haven't implemented yet now that I'm thinking about it), so I think the should be enough to check for alpha equivalence.

Idrall/Check.idr Outdated Show resolved Hide resolved
Idrall/Check.idr Outdated Show resolved Hide resolved
let x = freshen (ctxNames ctx) (closureName bT) in do
b' <- evalClosure bT (VNeutral aT (NVar x))
case i of
Prim => readBackTyped ctx b' (f VPrimVar) -- TODO double check b' here
Copy link

Choose a reason for hiding this comment

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

Hmm... shouldn't we get back a lambda from this? Maybe we already do?

Copy link
Owner Author

@alexhumphreys alexhumphreys Nov 8, 2020

Choose a reason for hiding this comment

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

Good question. Not sure exactly what this reads back to, or what values would cause this case to be hit, but it's pretty similar to Andras's version dhall-lang/dhall-haskell@627a6cd#diff-fb8fa4dd3e70181d66f30003f0f14a64f9ffb4d382266ddcf15746f09cd6ad91R776
line 753/776 of eval.hs

readBackUnion : Ctx -> (FieldName, Maybe Value) -> Either Error (FieldName, Maybe (Expr Void))
readBackUnion ctx (k, Nothing) = Right (k, Nothing)
readBackUnion ctx (k, Just v) = Right (k, Just !(readBackTyped ctx (VConst CType) v))
-- TODO is (VConst CType) always right here ^^^? Looks like rBT ignores the Ty param when reading back VConsts so maybe?
Copy link

Choose a reason for hiding this comment

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

I think it is fine, since you are only using it for the type

Copy link
Owner Author

Choose a reason for hiding this comment

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

Aye, was thinking so too. Andras's branch doesn't have a type param at all for reading back, not sure the implications of that, so I guess when reading back the straight forward type values (VType, VKind, VBool) should be safe to ignore that type param.

Idrall/Check.idr Outdated Show resolved Hide resolved
Idrall/Check.idr Outdated
b' <- synth ctx b
isTypeKindSort ctx b'
Right (k, Just b')
getHighestType : (acc : Either Error Ty) -> Maybe Ty -> Either Error Ty
Copy link

Choose a reason for hiding this comment

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

🚬

Copy link
Owner Author

Choose a reason for hiding this comment

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

haha 🤣

Alex Humphreys added 11 commits November 10, 2020 13:33
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Sometimes you need to compare VHPi and VPi directly like in the
following case:

```
let x = < Foo : Natural >.Foo
in let y = \(Foo : Natural) -> < Foo : Natural >.Foo Foo
in let list = [x, y]
in list
```

Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
Signed-off-by: Alex Humphreys <alex.humphreys@here.com>
@alexhumphreys alexhumphreys merged commit 3be7290 into master Nov 10, 2020
@alexhumphreys alexhumphreys deleted the feat/union-field branch November 10, 2020 12:34
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

Successfully merging this pull request may close these issues.

2 participants