-
Notifications
You must be signed in to change notification settings - Fork 439
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
Updates builtin type Map so that it stores Maybes in its nodes. #743
Conversation
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.
Why are you changing the Map
type? You didn't even mention that in the PR.
Also please update the PR name to something more succint, its a bit confusing.
I'm not against having Bool
in the prelude, but we don't really need it for anything builtin.
tests/snapshots/encode_pattern_match__match_adt_unscoped_lambda.bend.snap
Outdated
Show resolved
Hide resolved
src/fun/builtins.bend
Outdated
return (unreachable(), map) | ||
|
||
# Checks if a node has a value on a given key, returning Maybe/Some if it does, Maybe/None otherwise | ||
def Map/get_check (map: Map(T), key: u24) -> (Map(T), Maybe(T)): |
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.
get_check
is not a great name. I prefer get_checked
but it's also not great.
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.
get_node?
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.
get
also gets the node
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.
get_wrapped?
src/fun/builtins.bend
Outdated
return (unreachable(), map) | ||
|
||
# Checks if a node has a value on a given key, returning Maybe/Some if it does, Maybe/None otherwise | ||
def Map/get_check (map: Map(T), key: u24) -> (Map(T), Maybe(T)): |
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.
get
also gets the node
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'll trust the tests are correct
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.
Looks good, good job
I think a new Rust version is messing with the checks, I'll fix it don't worry |
Can you rebase and try again? |
…as the Maybe type Updates builtin type Map so that it stores Maybes in its nodes. Implement builtin type Map, and its corresponding functions, as well as the Maybe type Updates builtin type Map so that it stores Maybes in its nodes. Changes made on 09-12-2024, includes fixing requests from HigherOrderCO#743 Fixes based on PR review Partially updates doc and follows requests from PR review Fixes documentation, makes tests return simpler values, deletes useless snapshot Removes map_tests.bend.snap
Summary of Changes
The following updates have been made to
builtins.bend
:New/Updated Types and Functions
1.
Maybe
2.
Map
Updated type definition:
Now, every
Node
stores aMaybe
type to explicitly represent the presence or absence of a value.Updated/added functions:
Maybe/unwrap
: Retrieves the value inside Maybe/SomeMap/set
: Inserts or updates a value in the map.Map/get
: Retrieves a value from the map, returning aMaybe
type.Map/map
: Applies a function to each value in the map.Map/contains
: Checks whether a key exists in the map.Map/get_check
: Retrieves a value and performs additional validation.Why remove unreachable() from Map nodes?
unreachable()
function incorrectly ignores type check and can often cause bugs where the type isn't checked for an entire branch altogether.*
does not tell you whether you merely hit an unused node, or if another function called unreachable().Tests
Documentation update
Partially updates documentation adding a section for the Maybe type and new Map functions