Repository navigation
v0.9.0
Pyfun 0.9.0
Native builds through mypyc, façade packages, and clearer errors for habits carried over from
Python. Two changes break code, so this is a minor release.
Breaking
-
Task.scopeandTask.startlose theScopeargument. Starting a task is now an effect,
spawn, andTask.scopeis the only thing that handles it:let session = Task.scope (async { Task.start (worker "a") Task.start (worker "b") return "both joined" })Task.start : Async unit ->{spawn} unitandTask.scope : Async a -> Async a. A function that
starts tasks carries->{spawn}in its type and can be called inside any scope's body. Starting a
task anywhere else is a compile error ("this starts a task outside anyTask.scope, so nothing
would own it"). To migrate, drop thescopeparameter and argument and pass the async body
straight toTask.scope. A real 11-module program needed four changed lines. (#147) -
A capitalized
letname is an error.let Some x = Some 1used to define a function called
Some. It now says the name reads as a constructor and points you atmatch. (#130)
New
-
Native builds.
pyfun build --native prog.pyfun -o outcompiles a program with
mypyc, and the result runs aspython out. It needs
pip install mypy setuptoolsand a C compiler. In native mode everymatchbecomes anif/isinstance
ladder, and functions and module-level values are annotated from their inferred types. On the
repository's benchmarks the mypyc build runs 1.3x to 13x faster than the plain Python output, and
the integer-arithmetic benchmark runs about 12x faster than hand-written Python. Multi-module
projects work too: a real 11-module program compiles whole, and its move generator runs about
1.5x faster.pyfun compile --nativealone also speeds up match-heavy code on plain CPython.
(#149, #151–#159, #161, #163, #166, #167) -
Façade packages.
pyfun add <package>installs a pip package that ships typedextern
declarations, copies them into your project, and records it in a newpyfun.toml.
pyfun installrestores every listed package on another machine, andpyfun removedrops one.
import Namefinds the vendored module after your own files. There's an example façade in
examples/facades/pyfun-textwrap. (#150, #152) -
Every lesson as a Jupyter notebook, in
docs/src/notebooks/, and the educator pack as a
printable PDF at/educators/educator-pack.pdf. (#143, #144) -
Editors: Helix indentation and textobjects; a Sublime Text package (
editors/sublime);
cross-file find-references and rename for type names in every LSP editor. (#141, #146, #132)
Improved
- Errors that answer the Python habit.
returnoutside a computation expression now says that
a function's value is its last expression, so you can dropreturn(#148), and"-" * 20points
you atString.repeat count string(#169). - Typed holes name what you asked for. A hole's
try:list puts a fit whose name matches the
hole first (?uppersuggestsString.upperfirst) and keeps prelude order instead of
alphabetical (#131). Both thetry:andor:lists end withand N morewhen they are cut, so
you can tell a shortlist from the whole set (#131, #165). - The Jupyter kernel runs async code.
asyncio.runworks in a cell, since the cell runs off the
kernel's own event loop, and a cell starting with:resetbegins a fresh session. (#143)
Fixed
- A top-level fold could overwrite a top-level binding.
let x = 100followed by a
List.fold (fun acc x -> …)at the top level leftxholding the last element, because the
inlined loop's variable was a module global. (#142)
Known issue
- In a native build,
==on anOptionor on a type whose values are also compared with<
can be wrong. mypyc compilesSome 1 == Some 1to an identity check when the class also
defines ordering, so it givesfalse. Plainpyfun runandpyfun compileare unaffected, and
so areSetandMap. The next release fixes it.
Thanks
To @PandaHUN777 and @amandeavor for the first outside contributions (#148, #165, #169).
Upgrading
pip install --upgrade pyfun-lang. Code that uses Task.scope needs the migration above, and a
capitalized let name needs renaming or rewriting as a match. Everything else is additive.