Skip to content

Conversation

@runarorama
Copy link
Contributor

@runarorama runarorama commented Aug 28, 2025

This PR adds ##BigInt and #BigNat primitives and operations on them.

Controversial decisions

This is implemented via a foreign convention to the Numeric.Natural and Integer Haskell types. It could have alternatively have been implemented by expanding the core Unison term language, which would require updating the runtime machinery as well. I feel that what I've done is a simpler solution, though perhaps not as flexible. For example it's more work to add a syntax for these types later if we want one.

@runarorama runarorama changed the title Builints for arbitrary precision integer arithmetic Builtins for arbitrary precision integer arithmetic Aug 28, 2025
@runarorama runarorama requested a review from dolio August 30, 2025 00:41
…rorama/bigintnat

# Conflicts:
#	unison-src/transcripts-using-base/all-base-hashes.output.md
#	unison-src/transcripts/idempotent/alias-term.md
#	unison-src/transcripts/idempotent/alias-type.md
#	unison-src/transcripts/idempotent/branch-squash.md
#	unison-src/transcripts/idempotent/builtins-merge.md
#	unison-src/transcripts/idempotent/emptyCodebase.md
#	unison-src/transcripts/idempotent/fix1532.md
#	unison-src/transcripts/idempotent/lib-install-local.md
#	unison-src/transcripts/idempotent/mcp.md
#	unison-src/transcripts/idempotent/move-all.md
#	unison-src/transcripts/idempotent/reflog.md
#	unison-src/transcripts/idempotent/reset.md
#	unison-src/transcripts/idempotent/undo.md
#	unison-src/transcripts/idempotent/upgrade.md
@runarorama runarorama marked this pull request as ready for review August 30, 2025 17:59
Copy link
Contributor

Choose a reason for hiding this comment

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

Good morning — what is this file? It looks like html but is has .txt extension. Was it checked in intentionally?

Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

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

LGTM but @dolio do you wanna take a peek?

Copy link
Member

@pchiusano pchiusano left a comment

Choose a reason for hiding this comment

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

Cool! We can always add new literal syntax later if we want.

Minor thing: Could you change names to Integer and Natural? Integer is the type of integers, plain and simple, there's nothing big about it.

I know the builtin names don't actually matter but I'd rather the names be consistent with what they end up being called in base. And I like "Integer" and "Natural" so much better.

Copy link
Contributor

@dolio dolio left a comment

Choose a reason for hiding this comment

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

Implementation looks good to me.

aryairani and others added 2 commits September 6, 2025 07:32
# Conflicts:
#	unison-src/transcripts/idempotent/alias-term.md
#	unison-src/transcripts/idempotent/alias-type.md
#	unison-src/transcripts/idempotent/builtins-merge.md
#	unison-src/transcripts/idempotent/emptyCodebase.md
#	unison-src/transcripts/idempotent/fix1532.md
#	unison-src/transcripts/idempotent/lib-install-local.md
#	unison-src/transcripts/idempotent/mcp.md
#	unison-src/transcripts/idempotent/move-all.md
#	unison-src/transcripts/idempotent/undo.md
#	unison-src/transcripts/idempotent/upgrade.md
@aryairani aryairani merged commit 0e30da9 into trunk Sep 7, 2025
44 of 45 checks passed
@aryairani aryairani deleted the runarorama/bigintnat branch September 7, 2025 06:19
@runarorama
Copy link
Contributor Author

runarorama commented Sep 7, 2025

Builtin names do matter, which is why I didn't pick Integer and Natural. They matter because of the way hash references in code are resolved. Currently, if you say foo : ##Int, then ##Int is ambiguous if there is a type with the hash ##Integer (since ##Int) is a hash prefix of ##Integer. Probably this is a bug though.

Not to worry, the plan is for the names of these types to be Integer and Natural in Base.

@aryairani
Copy link
Contributor

Currently, if you say foo : ##Int, then ##Int is ambiguous if there is a type with the hash ##Integer (since ##Int) is a hash prefix of ##Integer. Probably this is a bug though.

Yeah this sounds like a bug.

@aryairani
Copy link
Contributor

@pchiusano Sorry I missed your comment about builtin names when merging; I saw Dan's "looks good" and hit the button. If you spot anything that shouldn't go into a release (settling on a builtin name qualifies IMO), don't hesitate to use the "Request Changes" review feature, to draw more attention to it.

@aryairani
Copy link
Contributor

We can still change the names before the next release

@pchiusano
Copy link
Member

Yeah, I'd change it in a quick follow up. Otherwise you are going to see ##BigInt on Share when viewing the type, and it'll appear in the URL sometimes. Just a needless weird difference.

I don't think inability to give type signatures that mention ##Int is a big deal, honestly. The only place that syntax is used, if anywhere, is in transcripts where we're too lazy to call builtins.merge or w/e.

@aryairani
Copy link
Contributor

I don't think ##BigInt is a terrible name though in any way; it's established in other libraries.
"Integer is a big Int and Natural is a big Nat because its identifier is bigger" honestly feels more cute than clear.

But yeah I only meant that we should settle on the name before the release.

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.

5 participants