Skip to content

v0.9.0

Choose a tag to compare

@github-actions github-actions released this 17 Oct 19:00
· 73 commits to main since this release
f7acdaf

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.scope and Task.start lose the Scope argument. Starting a task is now an effect,
    spawn, and Task.scope is 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} unit and Task.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 any Task.scope, so nothing
    would own it"). To migrate, drop the scope parameter and argument and pass the async body
    straight to Task.scope. A real 11-module program needed four changed lines. (#147)

  • A capitalized let name is an error. let Some x = Some 1 used to define a function called
    Some. It now says the name reads as a constructor and points you at match. (#130)

New

  • Native builds. pyfun build --native prog.pyfun -o out compiles a program with
    mypyc, and the result runs as python out. It needs
    pip install mypy setuptools and a C compiler. In native mode every match becomes an if/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 --native alone 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 typed extern
    declarations, copies them into your project, and records it in a new pyfun.toml.
    pyfun install restores every listed package on another machine, and pyfun remove drops one.
    import Name finds 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. return outside a computation expression now says that
    a function's value is its last expression, so you can drop return (#148), and "-" * 20 points
    you at String.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 (?upper suggests String.upper first) and keeps prelude order instead of
    alphabetical (#131). Both the try: and or: lists end with and N more when they are cut, so
    you can tell a shortlist from the whole set (#131, #165).
  • The Jupyter kernel runs async code. asyncio.run works in a cell, since the cell runs off the
    kernel's own event loop, and a cell starting with :reset begins a fresh session. (#143)

Fixed

  • A top-level fold could overwrite a top-level binding. let x = 100 followed by a
    List.fold (fun acc x -> …) at the top level left x holding the last element, because the
    inlined loop's variable was a module global. (#142)

Known issue

  • In a native build, == on an Option or on a type whose values are also compared with <
    can be wrong.
    mypyc compiles Some 1 == Some 1 to an identity check when the class also
    defines ordering, so it gives false. Plain pyfun run and pyfun compile are unaffected, and
    so are Set and Map. 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.