Add default keyword for generating a default value of any type#2683
Merged
mergify[bot] merged 5 commits intomainfrom Feb 2, 2026
Merged
Add default keyword for generating a default value of any type#2683mergify[bot] merged 5 commits intomainfrom
default keyword for generating a default value of any type#2683mergify[bot] merged 5 commits intomainfrom
Conversation
Co-authored-by: Restyled.io <commits@restyled.io>
xsebek
approved these changes
Feb 2, 2026
Member
xsebek
left a comment
There was a problem hiding this comment.
Nice 👍 I was surprised it tried the right branch as well.
| -- (rec l. (Int * l) + Unit). Since we default to generating the left | ||
| -- side of a sum type, this will recurse forever generating inl (0, | ||
| -- inl (0, inl (0, ...))). To support recursive types we would have | ||
| -- to do more sophisticated analysis to find a finite value to pick. |
Member
There was a problem hiding this comment.
Would a set of encountered types (?) in recursion do the trick? 🤔
It seems the only possible problem are loops and we should be able to detect them if types have Ord.
Member
Author
There was a problem hiding this comment.
Oh, good idea. Your comment was just what I needed to see how to make it work. It wasn't all that hard in the end, so I added it. 😄
Contributor
Merge Queue Status✅ The pull request has been merged at 31f923b This pull request spent 14 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
defaultmust be applied to a type literal, i.e.default @Intordefault @(Text -> Int)or whatever. It can also be used with type synonyms, as intydef X = [... record type ...] end; default @X. It is replaced with a default value at compile time, sodefaultnever has to be interpreted at run time. Making it generate a default value at run time would be more flexible (it would allow e.g. higher-order uses) but getting access to a relevant context of type synonyms at runtime is tricky, so I figured static compile-timedefaultvalue generation would be simpler.defaultshould support all inhabited types, including recursive types that have finite values.Currently,
defaultrequires no special capability to use, but I could be convinced otherwise.Closes #2192.