Skip to content

v0.19.0

Latest

Choose a tag to compare

@Ikepeeee Ikepeeee released this 24 Nov 16:12
ebf8fd8

Lask gets type classes, and a project's tasks are reachable from anywhere in it.

v0.19.0 adds classes and instances (spec 4.6). A class declares methods over a type, an instance defines them for one type, and a class is used as a bound, <T: ord>. Which instance runs is decided while the program is checked, from the types, so a generic task is specialized at each type it is used at and within is checked for each one. orderable is now a class that is open to instances, so sort, < and compare work on your own types. On the command line, lask looks for main.lask in the directories above the current one, and a function in a re-exported namespace is named by its path as words, lask run db migrate. Completion offers what may be written at the cursor, and a stack trace says where in each function the failure was.

Breaking changes

  • orderable no longer entails stringifiable (spec 4.2, 4.6). A body that interpolates a value of an orderable type parameter declares it <T: orderable + stringifiable>.
  • lask looks for main.lask in the directories above (spec 11.2). Without --module, a command run in a directory with no main.lask now uses the nearest one above it. No main.lask up to the root, and a --module that names no file, are E-CLI-USAGE (exit 4), not E-NAME-UNDEFINED (exit 1).
  • A stack trace frame says where the failure was: at lint (main.lask:25:3), not lint (main.lask). The innermost frame gives the expression that failed, and each frame after it the call the failure came out of. A function the language makes is shown as async, try, finally or lambda, not <lambda@15:7>.
  • A function of a re-exported namespace is written as its path in words in the help, the function list, usage errors and completion: db migrate, not db.migrate. JSON output, confirm keys, the default confirmation phrase and logs keep the declared name, db.migrate.
  • lask cmd --help writes an environment as run --help and envs list do, #golang:1.25 registry, not docker golang:1.25. Its JSON is unchanged.

Lask is pre-1.0 and every feature is experimental until 1.0, so breaking changes remain possible; see compatibility.md.

Classes and instances

  • class declares methods over one type parameter, with signatures and optional defaults: class ord<T: comparable> { cmp(a: T, b: T): Number }. The class's own bound is its superclass. class and instance are contextual keywords, so both remain usable as names.
  • instance defines the methods for one type: instance ord<Version> { cmp(a, b) = ... }. An instance is for the type after aliases are expanded. A program has one instance per class and type, declared in the class's module or in the project, never in a dependency.
  • Parametric instances: instance<T: orderable> orderable<Array<T>> { ... } is an instance for every Array<X> whose X is orderable. Two instances whose types overlap are E-NAME-DUPLICATE.
  • A class is a bound, bare or through a namespace (<T: m.ord>). A parameter without an annotation takes the bound of the methods it is passed to.
  • orderable is a class with the method compare(a, b): Number. instance orderable<Version> gives a type an order that sort, sort_by, compare and < <= > >= use. comparable and stringifiable are closed: an instance of either is E-TYPE-INSTANCE.
  • Bounds join with +: <T: orderable + stringifiable>. Inference joins what a parameter's uses need, less what another use entails, instead of rejecting two bounds neither entails. A part written twice, or entailed by another, is the new advisory W-BOUND-REDUNDANT.
  • The CLI picks the instance from the decoded arguments (spec 11.2). A JSON object is a record type, and an instance type with Number, String or Bool in place of its parameters selects among the types a parametric instance gives.
  • New error code E-TYPE-INSTANCE. A class-bounded type parameter or a class method that never mentions the parameter is E-TYPE-ILLFORMED, and a generic that recurs at ever larger types is E-TYPE-BOUND at the declaration that recurs.
  • A new language topic, example/02-language/15-classes, walks through all of it.

Types

  • A function argument may take more than the callee passes it (spec 4.4). for_each(xs, show) with show: Function<Any, Void> is well-typed, and so is a lambda whose parameter is annotated wider than the element type. >> and << accept a second function that takes more than the first returns. Value arguments are still matched exactly.
  • Instantiation does not depend on argument order. When the arguments give a variable two types and one is wider, the variable takes the wider one, and < takes the wider operand as == does. An empty literal takes the type of the other side, so [] == xs and eq([], xs) type-check.
  • An expected type of Any instantiates no type variable, so to_json(largest([1, 2])) type-checks and the arguments decide.
  • A call to another declaration in a cycle is instantiated at the types it is given, so mutually recursive generics no longer depend on their type parameters sharing a name.
  • A type error in a call is reported in the call's own terms ("this function takes Number, but 'map' passes it String"). An arity error shows what the call should look like, and under |> it says that the operand is not added to the call's arguments.

Command line

  • A function in a re-exported namespace is named by its path, as words or joined by .: with export * as db from "./db.lask", both lask run db migrate and lask run db.migrate work, through any number of namespaces. lask run db --help lists what db holds, and a bare lask run db is E-CLI-USAGE naming what may follow it. envs and secrets take the path the same way. Completion follows export * as.
  • A task runs from anywhere in its project: main.lask is found in the nearest directory above. Paths stay relative to the module's directory. fmt, deps and secrets still work outside a project, and shell completion finds the same module.
  • Naming an internal function, in the entry module or in a module a namespace refers to, says it is internal and names its module, instead of "no such function".
  • lask envs, lask deps, lask secrets and a bare lask print "a subcommand is needed" and the group's help, still with exit 4.
  • lask sync prints a progress heading only when something is under it.
  • The REPL has :help (:h, :?), and places a diagnostic in what was typed (<repl>:1:20).

Language server

  • Completion offers what may be written at the cursor. In a type annotation it offers the types in scope, the declaration's type parameters, namespaces and the built-in types. After within it offers the access constraints. Inside the braces of an access constraint or of run options it offers the fields not yet written. Keyword parameters the call already binds are no longer offered, and the contextual keywords are offered with the reserved words. Over example/, with one character typed, the name being written is now offered at 87.6% of positions (40.4% before), and in types at 100%.
  • class and instance are highlighted as keywords where they begin a declaration.

Fixes

  • An internal class is not reachable through a namespace, as a bound or as an instance's class.
  • An expected type that instantiates a variable at Any is held to its bounds, so to_json(empty()) for a class method is E-TYPE-BOUND, not a runtime failure.
  • Checking a large module with no classes takes about as long as it did before classes were added (within 2-3%).