Repository navigation
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
orderableno longer entailsstringifiable(spec 4.2, 4.6). A body that interpolates a value of anorderabletype parameter declares it<T: orderable + stringifiable>.lasklooks formain.laskin the directories above (spec 11.2). Without--module, a command run in a directory with nomain.lasknow uses the nearest one above it. Nomain.laskup to the root, and a--modulethat names no file, areE-CLI-USAGE(exit 4), notE-NAME-UNDEFINED(exit 1).- A stack trace frame says where the failure was:
at lint (main.lask:25:3), notlint (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 asasync,try,finallyorlambda, 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, notdb.migrate. JSON output,confirmkeys, the default confirmation phrase and logs keep the declared name,db.migrate. lask cmd --helpwrites an environment asrun --helpandenvs listdo,#golang:1.25 registry, notdocker 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
classdeclares 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.classandinstanceare contextual keywords, so both remain usable as names.instancedefines 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 everyArray<X>whoseXisorderable. Two instances whose types overlap areE-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. orderableis a class with the methodcompare(a, b): Number.instance orderable<Version>gives a type an order thatsort,sort_by,compareand<<=>>=use.comparableandstringifiableare closed: an instance of either isE-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 advisoryW-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,StringorBoolin 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 isE-TYPE-ILLFORMED, and a generic that recurs at ever larger types isE-TYPE-BOUNDat 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)withshow: 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[] == xsandeq([], xs)type-check. - An expected type of
Anyinstantiates no type variable, soto_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
.: withexport * as db from "./db.lask", bothlask run db migrateandlask run db.migratework, through any number of namespaces.lask run db --helplists whatdbholds, and a barelask run dbisE-CLI-USAGEnaming what may follow it.envsandsecretstake the path the same way. Completion followsexport * as. - A task runs from anywhere in its project:
main.laskis found in the nearest directory above. Paths stay relative to the module's directory.fmt,depsandsecretsstill 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 secretsand a barelaskprint "a subcommand is needed" and the group's help, still with exit 4.lask syncprints 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
withinit 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. Overexample/, with one character typed, the name being written is now offered at 87.6% of positions (40.4% before), and in types at 100%. classandinstanceare 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
Anyis held to its bounds, soto_json(empty())for a class method isE-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%).