stdlib: give Set and Map their traversal half - #46
Merged
Conversation
Both were containers you could build, query for membership and convert, but not walk. Transforming either meant a round trip through toList, which is the kind of gap that makes a standard library feel unfinished even though nothing is strictly missing. Set gains isEmpty, map, filter, fold, exists, forall, partition, isSubset, isSuperset, max and min. Map gains isEmpty, map, filter, fold, exists, forall, partition and union. Every Map member takes the key *and* the value, since a map's element is the pair, and walks m.items() so each entry is read once — a loop over keys with m[k] inside would hash every key twice. Map.map keeps the keys and frees the value type (Map k v -> Map k w); Map.union lets the second map win a shared key. Set.map can return a smaller set, since two elements may map onto one, so its result type is free rather than a relabelling. Set.max and Set.min answer with Option and carry the comparison constraint, like List.max. Set.fold walks in Python's set order, which is not sorted, and its documentation says so rather than leaving it to be discovered. Both partitions test each element once, as List.partition does: the two-pass form would double the predicate's effects as well as its cost.
This was referenced Jul 31, 2026
Merged
simontreanor
added a commit
that referenced
this pull request
Jul 31, 2026
Two dogfooding reports from real programs, and the standard-library sweep they triggered. Language: * a `type` declaration can name an imported type, bare or module-qualified (#36) — the one gap that changed a program's architecture rather than its phrasing, forcing two modules into one file * field access resolves from the base's type when it is known, so two records may share a field name without prefixes (#37) * parameters destructure: tuples (#38), records (#40), and `_` * a direct self tail call lowers to a loop, so an interactive turn loop no longer walks the stack (#39, #41) Standard library — about 115 new members, taking every module to the F# core set: List (#42), Seq (#44), Set and Map (#46), String (#47), Option and Result (#48), then a member-by-member FSharp.Core audit (#51). Every built-in member now carries a one-line description and its complexity in hover and completion (#43, #49), enforced by tests. Fixes: * `pyfun run` on a single file gives the program its own stdin, so an interactive program is runnable by the command whose job is running programs (#35) * a partially applied lambda closes over its argument instead of being wrapped, so `List.map ((+) 2)` emits `lambda b: 2 + b` (#52) * every multi-argument callback's scheme put the effect variable on the wrong arrows, so `List.fold` could never accept an effectful folder (#51) * `Seq.empty` lowered to a bare `iter()`, a TypeError (#51) One source-incompatible change, which is why this is 0.4.0 and not 0.3.1: a dotted `extern` target whose module prefix cannot be decided from the text is now a compile error naming the `extern import` to add (#50). `sys.stdout.flush` used to emit `import sys.stdout` and fail at runtime; declaring `extern import sys` fixes it.
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.
Dogfooding finding #5, PR 3 of 5 (see #34). Follows #42 (
List), #43 (docs) and #44 (Seq).SetandMapwere containers you could build, query for membership and convert, but not walk. Transforming either meant a round trip throughtoList— the kind of gap that makes a library feel unfinished even when nothing is strictly missing. This adds 19 members.isEmptymapfilterfoldexistsforallpartitionisSubsetisSupersetmaxminisEmptymapfilterfoldexistsforallpartitionunionDesign points worth review:
Mapmember takes the key and the value, since a map's element is the pair, and walksm.items()so each entry is read once. A loop over keys withm[k]inside would hash every key twice; there's a test asserting the emitted helper does neither.Map.mapkeeps the keys and frees the value type (Map k v -> Map k w), whileSet.mapfrees the element type entirely (Set a -> Set b) and can return a smaller set, since two elements may map onto one. Both have tests.Map.unionlets the second map win a shared key, matchingdict.updateand Python's{**a, **b}.Set.max/Set.minanswer withOptionand carrycomparison, followingList.max.Set.foldwalks in Python's set order, which is not sorted. Its documentation says so rather than leaving it to be discovered by a fold whose answer depends on order.List.partitiondoes.All the higher-order members are effect-polymorphic like
List.map, with tests thatlet purerejects an impure traversal in each module.Tests: 8 typecheck cases, 3 lowering assertions (items-walk, single-evaluation partition, Python's own set methods), and 2 end-to-end programs covering all 19 members' runtime results. Full suite, clippy and fmt clean.