Repository navigation
v0.6.0
v0.6.0
Four bugs found while writing ordinary Pyfun programs, and the two of them that
needed a semantic change brought a breaking change with it. Types now cross
module boundaries as completely as values already did, and a misplaced line
inside a computation expression says so where it happens.
Breaking changes
Pyfun is below 1.0 and changes the language when a rule turns out to be wrong.
Both changes below reject code that 0.5.0 accepted, and both replace silence or
a misleading message with an accurate one.
A local type may no longer share a name with an imported extern type.
An extern type now crosses module boundaries, so a consumer that declares its
own type of the same name gets an import clash. In 0.5.0 the opaque type did not
cross at all and the two nominal types were quietly treated as one. Rename either
type to fix it.
Inside a computation expression, an argument line may not open left of the
expression it continues. This is rejected:
result {
let! x = Option.toResult "bad"
(String.toInt n)
return x
}
Indent the argument past the start of Option.toResult, or put the whole
expression on its own lines below let! x =. In 0.5.0 the layout parsed, and a
statement written the same way was swallowed as arguments and surfaced as a type
error on the line above naming a type nobody wrote.
Fixed
An extern type can be named across a module boundary (#72). A module's
interface carries its opaque handle types, so Gen.Rng can be written in a
record field, an ADT payload, or an extern signature. Values of the type always
crossed; now the name does too. The workaround of wrapping the type in a record
just to have a name another module may say is no longer needed.
A record reached through another module's exports has its fields (#75).
Interfaces close over what they reference: a record or opaque type mentioned by
an exported scheme, constructor, or record field is carried along, tagged with
the module that declares it, through as many hops as it takes. A third module can
hold a value, read its fields, and name its type without importing the module two
steps away.
A carried type crosses as an identity rather than as a member. Constructing it,
pattern matching it, or writing its qualified name still asks for a direct
import, and the error says which module to import. For field lookup on a value
whose type is not yet known, records this module declares and records it imports
directly decide the lookup, and carried records are consulted only when neither
does. Every lookup that resolved in 0.5.0 resolves the same way.
A statement after a binding in a computation expression is reported where it
is (#64). Items inside the braces are structured by indentation, so a line that
is not indented past the item above it sits in item position and must start with
let!, let, do!, return, or yield. A line that is indented gets a
message naming the item it continues and both ways to fix it:
error: identifier `print` is indented as a continuation of the `let` item on line 4,
where it can only be an argument to that item's expression; to make it a new item,
align it with that item and bind its value (`let _ = ...`), or indent it past the
start of the expression to continue it
pyfun run forwards program arguments (#73). Everything after the source
path reaches the program's sys.argv, with or without a -- separator, so a
program behaves the same under run as it does compiled. Arguments that look
like flags are passed through rather than read by the CLI.
Improved
Rendered lex and parse errors no longer end with a byte span that repeats the
line and column already shown above the caret. Editors get the bare message
alongside the range they already had, and the same text now reaches the REPL and
the Jupyter kernel.
The playground compiles the current compiler and demonstrates the features added
since it was written, and the learning site covers what 0.4.0 and 0.5.0 added.
Upgrading
pip install --upgrade pyfun-lang. If a project stops compiling, it is one of
the two breaking changes above, and each has a one line fix.