Conversation
A `fn A, ...: R` in type position describes a function type -- a `$FnType` value, sibling to `$RecType`/`$TupleType` (not a subtype: a function is not a tuple). It carries the arg types (`$params`, reverse-stored list) and the result type (`$result`), minted by accretion like the tuple family: new_fn_type seeds it, fn_type_param cons-prepends each arg type, fn_type_result sets the result. `Foo = type: fn A: R` makes `Foo` the named function type directly (a sole `fn` body is the type itself, not a tuple wrapping it). Function types compare by identity via the existing deep_eq ref.eq fallback: distinct declarations differ, aliases are equal. As a match/bind guard a function type is well-defined and runs, but matches nothing yet -- instances are unconstructable. In type position a `fn`'s params are type REFERENCES, not binding sites (as they are for a fn value), so the scopes pass resolves them as references in the type scope rather than registering param binds. Deferred: rendering a bare type value (repr_val/fmt_val have no $Type arm -- only values and instances render today; two repr tests pin the target and are skipped), and typed-function instances (no type_apply $FnType arm).
|
📦 This PR will release v0.89.0 (minor) when merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A
fn A, ...: Rin type position describes a function type -- a$FnTypevalue, the third type flavour alongside$RecType/$TupleType. It is a sibling, not a subtype (a function is not a tuple), carrying the argument types ($params, a reverse-stored list) and the result type ($result).This is the keystone for describing protocols in fink: a protocol is a record of named function types.
Behaviour
Foo = type: fn A, B: R. A solefnbody makesFoothe named function type directly (not a tuple wrapping it).deep_eqref.eqfallback -- distinct declarations differ, aliases are equal. No new equality code.How
$FnTypesibling struct;new_fn_type/fn_type_param/fn_type_resultruntime funcs, accreted like the tuple family.lower_type_exprmints a$FnTypefor afnin type position; a sole-fntype body becomes the named fn type; three newBuiltIns thread the construction.fn's params are type references, not binding sites -- resolved in the type scope rather than registered as param binds. (This is the one upstream-pass change; it fixes param type-names resolving to unbound.)Deferred (flagged in tests + comments)
repr_val/fmt_valhave no$Typearm -- only values and instances render today, never type values themselves. Two repr tests pin the target output (Foo fn u8: u8) and areskip'd.type_apply$FnTypearm. Constructingfoo = Foo fn ...: ...(a closure tagged with its type, enabling runtime arg-checking on invocation) is a separate, larger increment touching$Closureandapply.Tests
Full suite green (1366 lib, 0 failures), clippy clean, zero snapshot drift (no existing test declares a function type, so the new path adds no churn). New fn-type tests: equality, aliasing, guard-falls-through.