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

Implement Natural/subtract #1133

Merged
merged 32 commits into from
Aug 2, 2019
Merged

Conversation

ocharles
Copy link
Member

@ocharles ocharles commented Jul 18, 2019

... as standardized in dhall-lang/dhall-lang#650

@ocharles ocharles added the wip Work in progress - the author is not yet asking for reviews label Jul 18, 2019
@AndrasKovacs
Copy link
Collaborator

AndrasKovacs commented Jul 18, 2019

The commented-out qApp should be there.

If you implement something as a curried constant with a type, then you need to qApp the appropriate number of parameters, which is the number of VPrim constructors in the implementation of eval for the constant.

@ocharles
Copy link
Member Author

ocharles commented Jul 18, 2019

Oh, it wasn't commented out before but it still fails to terminate with it. Let me push that.

@ocharles
Copy link
Member Author

Ok, pushed that corrected version (but it still gets stuck)

@f-f
Copy link
Member

f-f commented Jul 18, 2019

@ocharles shouldn't NaturalTruncatedSubtract constructor be more like NaturalPlus (i.e. containing two values) than like NaturalShow? (with no values attached, which is how it is currently)

@AndrasKovacs
Copy link
Collaborator

@f-f yeah that would work. It's also possible to do the curried version (I'm going to paste here that in a minute), but if partial application is not possible in the syntax, there is no reason to define NaturalTruncatedSubtract as curried.

@ocharles
Copy link
Member Author

I believe it's because partial application should be allowed. All the other terms are infix operators, I believe.

@AndrasKovacs
Copy link
Collaborator

OK, give me some time plz I'm a bit confused why this loops

@ocharles
Copy link
Member Author

Of course, no rush from my part!

@sjakobi
Copy link
Collaborator

sjakobi commented Jul 18, 2019

I guess I'm a bit late to the discussion. But wouldn't a function Natural -> Natural -> Optional Natural be slightly more useful? I mean

2 - 1 = Some 1
1 - 1 = Some 0
1 - 2 = None Natural

You could then use Optional/fold to derive truncated subtraction.

Less-than and equals operations would be very straightforward to implement.

(I suspect this was considered before but decided against for some reason?)

@ocharles
Copy link
Member Author

@sjakobi See dhall-lang/dhall-lang#602 (comment) - I believe I'm implementing faithfully to the linked comment.

@AndrasKovacs
Copy link
Collaborator

AndrasKovacs commented Jul 18, 2019

@ocharles You forgot to add NaturalTruncatedSubtract to prettyPrimitiveExpression in Pretty/Internal.hs. There's an evil default case there suppressing the pattern match warning. It works if you fix this.

@ocharles
Copy link
Member Author

Oh man, that's horrific. I knew it must have been a type class spinning somewhere, thanks for taking the time to dig into that for me!

@ocharles ocharles removed the wip Work in progress - the author is not yet asking for reviews label Jul 18, 2019
@Gabriella439
Copy link
Collaborator

Yeah, the pretty-printing infinite loop is a common land-mine that people stumble upon when making contributions (myself included). If anybody knows how to fix it I'll make the change

@joneshf
Copy link
Collaborator

joneshf commented Jul 18, 2019

One option is to remove the default and handle the 20 other cases explicitly.

@ocharles ocharles changed the title Implement Natural/truncatedSubtract Implement Natural/subtract Jul 19, 2019
@Gabriella439
Copy link
Collaborator

This pull request seems to have the Lift-related work. Is that intentional?

@ocharles
Copy link
Member Author

Sort of. I was lazy and didn't start from master. I could debase, but I assumed the Lift stuff would go through

@ocharles
Copy link
Member Author

Note that I planned to merge them sequentially, so they will still be split into separate commits

@Gabriella439
Copy link
Collaborator

@ocharles: I still think we should unbundle the Lift-related changes from this pull request, otherwise we'll have to block this pull request on the other one being merged first

@ocharles
Copy link
Member Author

Yep, will do. I was lazy and just thought that would have been merged by now, but it's turning out more complicated!

@ocharles
Copy link
Member Author

@Gabriel439 good to merge now that the new version is out?

@ocharles
Copy link
Member Author

Just remembered I need to bump the submodule, I'll do that before merging and make sure the tests pass.

@Gabriella439
Copy link
Collaborator

I think if you merge in master it will fix the test failure that you are running into

@ocharles
Copy link
Member Author

ocharles commented Aug 1, 2019

@Gabriel439 Nope. I'm not sure dhall-lang master works with dhall-haskell yet.

@sjakobi
Copy link
Collaborator

sjakobi commented Aug 1, 2019

@ocharles I think you should checkout dhall-lang/dhall-lang@c7082d9 for dhall-lang. The change in the failing parser test is more recent.

I believe isNormalized needs a bit more work too. Maybe up the frequency of NaturalSubtracts a bit and increase the maxSuccesses for the quickcheck test.

@sjakobi
Copy link
Collaborator

sjakobi commented Aug 1, 2019

I believe isNormalized needs a bit more work too. Maybe up the frequency of NaturalSubtracts a bit and increase the maxSuccesses for the quickcheck test.

…at least temporarily so you can see the failing cases more reliably.

@ocharles
Copy link
Member Author

ocharles commented Aug 1, 2019

Thanks for the tip @sjakobi! That did indeed reveal a problem. I think we're good to go now.

@mergify mergify bot merged commit 1b68329 into dhall-lang:master Aug 2, 2019
@ocharles ocharles deleted the truncatedSubtract branch August 2, 2019 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants