stdlib: the FSharp.Core audit, and the effect-arrow bug it found - #51
Merged
Conversation
Comparing the surface member by member against FSharp.Core turned up 21 additions, nearly all from *internal* asymmetry rather than parity alone: takeWhile and dropWhile existed on Seq but not List; nine List members had no Seq counterpart (empty, distinctBy, replicate, get, last, sumBy, max, min, reduce); iter existed on List, Seq, Option and Result but not on Set or Map; Option.exists had no forall; and sign was the one F# global with no equivalent. List also gains sortByDescending, which sortBy and sortDescending implied, and countBy. The more valuable half is a bug. Every scheme with a multi-argument callback put the effect variable on *every* arrow, but a function's latent effect lives on its innermost arrow, so an impure two-argument callback could never unify: it wants pure outside and io inside, while the scheme demands one answer for both. That silently made every such member pure-only — List.fold could not print. Thirteen schemes across List, Seq, Set, Map, Option and Result now carry the effect on the innermost arrow alone, which accepts pure and impure callbacks alike and lets the effect flow out to the call, exactly as the one-argument members always did. Two smaller finds while wiring it up: Seq.empty lowered to a bare `iter()`, which is a TypeError rather than an empty iterator, and my first `sign` used a `num_vars` entry on a plain type variable, which constrains nothing — the numeric constraint is the dedicated `Ty::Num`, as `abs` uses.
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.
The audit pass that closes dogfooding finding #5 (see #34). Depends on nothing else; #50 (the import diagnostic) is independent.
Comparing the surface member by member against
FSharp.Coreturned up 21 additions — and one bug that matters more than all of them.The bug
Every scheme with a multi-argument callback put the effect variable on every arrow. A function's latent effect lives on its innermost arrow (DESIGN §4), so an impure two-argument callback wants pure outside and
ioinside, while(b ->{e} a ->{e} b)demands one answer for both. Nothing effectful could ever unify, which silently made every such member pure-only:Before:
effect mismatch: cannot unify 'a -> 'b -> 'a with int -> int ->{io} int.List.foldcould not print. After: it checks, andlet pureon it correctly reportsperforms `io`.Thirteen schemes across
List,Seq,Set,Map,OptionandResultnow carry the effect on the innermost arrow alone — strictly more permissive, so nothing that compiled before stops. There's a test asserting one shape per module so it cannot regress.The 21 members
Nearly all from internal asymmetry rather than F# parity:
List(4):takeWhiledropWhile—Seqhad them; plussortByDescending(whichsortByandsortDescendingimplied) andcountBy.Seq(9):emptydistinctByreplicategetlastsumBymaxminreduce— all of whichListalready had.Set/Map(2):iter, which existed onList,Seq,OptionandResultbut neither of these.Option/Result(5):Option.forall/contains;Result.exists/forall/contains.forallpasses onNoneand onError— the empty case, asList.forallpasses on[].sign, the one F# global with no equivalent.Two smaller finds while wiring it up
Seq.emptylowered to a bareiter(), which is aTypeError, not an empty iterator. Nowiter([]), with a test.signused anum_varsentry on a plain type variable, which constrains nothing —sign "x"type-checked. The numeric constraint is the dedicatedTy::Num, asabsuses. Caught by its own test.Deliberately not added:
foldBack/reduceBack/scanBack(no reverse-order idiom here),transpose/permute/splitInto/allPairs/zip3(niche),mapi(indexedplus a tuple parameter now covers it),singleton([x]),Seq.cache(the single-pass caveat is documented rather than papered over).Tests: 7 typecheck cases including the multi-argument-effect regression across all nine affected members, 2 lowering assertions, and an end-to-end program covering all 21. Full suite, clippy, fmt and the 23 doc lessons clean.