Repository navigation
v0.10.0
Pyfun 0.10.0
async { } now behaves like F#'s async: nothing runs until it is awaited, and every await is a
fresh run. Native builds are checked against plain runs on every change, and the compiler answers
more Python habits with the Pyfun spelling. One change breaks Python code that runs a Pyfun async
value directly, so this is a minor release.
Breaking
-
An
Asyncvalue is cold. Building one runs nothing, and every await is a fresh run, as in
F#'sasync:let roll = async { print "rolling" return 6 } let twice = async { let! a = roll let! b = roll return a + b }twiceprintsrollingtwo times and returns12. Before, the secondlet!raised
RuntimeError: cannot reuse already awaited coroutine, andAsync.parallel [roll, roll]ran
rollonce.Nothing starts before it is awaited, and that changes one pattern. An extern over a Python call
that starts work as soon as it is called (a call returning anasyncioTask, or a browserfetch
promise under Pyodide) used to overlap when written like this:let a = fetch url1 let b = fetch url2 let! x = a let! y = bNow
bstarts only afterafinishes, and awaiting one value twice makes the request twice.
Nothing fails, it is just slower. To overlap requests, hand them toAsync.paralleltogether:
let! pages = Async.parallel [fetch url1, fetch url2].Python code handed a Pyfun
Asyncnow receives an
awaitable rather than a coroutine: it can await it any number of times, or call it for a fresh
coroutine as it would anasync def. To migrate, writeasyncio.run(job())where Python ran a
Pyfun value withasyncio.run(job)(Python 3.14 accepts either; 3.12 and 3.13 need the call).
Async callbacks handed to Python, such as anasyncio.start_serverhandler, are adapted so
Python receives real coroutines. (#177)
Fixed
==in a native build. A sum type the program compares with<gavefalsefor
Some 1 == Some 1once mypyc compiled it, and<=/>=stopped the build. (#172)- A native build of an async self tail call failed to compile on Linux and crashed on Windows
(a mypyc bug, python/mypy#22221). (#174, and #177 removes the shape altogether) - A multi-line string in a file saved on Windows carried a carriage return before every
newline. A line break in a string is now\nwhatever the file's line endings, as in Python.
(#182) - A file named like
01-intro.pyfunbuilds natively. (#172) pip install mypy setuptoolsis the install line for native builds: a fresh Python 3.12+
venv has nosetuptools, which mypyc needs. (#172)
Improved
- Errors that answer the Python habit:
def area w h = …says to writelet area w h = …;
an unboundlen,str,sumand eleven other builtins name their Pyfun spelling;&&and||
sayandandor; and[1, 2] + [3]points atList.concat xs ys. (#164, #168, #175, #176) - A callback that misses an extern's closed arrow points at
->{e}. Handing anasync { }
handler toextern serve: (Reader -> Writer -> Async unit) -> …used to fail with "effect mismatch:
cannot unify …" under the whole call. It now says what the handler performs, what the extern's
arrow allows, and to write the arrow as->{e}, rather than pasting in the handler's own
effects, which would accept only handlers doing exactly that. (#181, found by a real
program, #180) - Native builds are checked on every PR against plain runs of every lesson program and
example. (#172)
Thanks
To @PandaHUN777 for the &&/|| and list-concatenation hints (#164, #168).
Upgrading
pip install --upgrade pyfun-lang. Python code that runs a Pyfun async value with
asyncio.run(job) should call it, asyncio.run(job()).