Jock beta parser changes#62
Conversation
|
Posting a note here about where I was headed with the beta branch. The state is that I had just implemented the parser for native The fundamental problem with the Jock alpha release was that the type system was ad hoc. That was fine for the time being, but obviously needed to be corrected. This showed up in two places:
I opted to back out to a Rust-style I've recently decided that this introduces subject scope issues and it's better to retain (You do want Anyway, here's a summary of where I was going in this branch, modulo the Struct(Note: see struct Point(x: @ y: @);Single-element Aliasesalias Path List<Chars> // transparent alias
struct UserId(Atom) // opaque single-field wrapper
struct Point(x: Atom y: Atom) // named fieldsThese need to be resolved at compile time because they have to be set within the current subject scope, i.e. not completely lazily. Example: alias Path = List<Chars>;
let p = /foo/bar/(segment)/baz;
let q = /;
let r = /users/(user-id as Chars)/profile;
(p q r)Traitstrait Arithmetic {
add(self other:Self) -> Self
neg(self) -> Self
}
I played a lot with terminology here. Also considered Trait Loss on Castimpl Arithmetic for Vec2 { ... };
let v = Vec2(1 2);
v.add(Vec2(3 4)) // OK
let p:Point = v as Point;
p.add(Point(3 4)) // Error: no impl for PointCast changes type label. Impl lookup uses new type. Traits don't follow the data. Unionunion Result {
case ok(value:Atom)
case err(code:Atom msg:Chars)
}Head-tagged cells: No generics on unions for v1. Pattern matching via Higher-Order Functionsfunc map<T U>(f: T -> U xs: List<T>) -> List<U> {
...
}
This feels more like a protocol/trait definition still and I want to play with alternatives. See Generics below. Lambdalambda (x: @ y: @) -> @ { x + y }Explicit types required on parameters and return. Objectobject {
func helper(n: @) -> @ { ... }
constant = 42
}Sample-less core, no Genericsfunc first<T>(xs: List<T>) -> ?T { ... }
let x = first([1 2 3]) // T = Atom, inferred from argument
let y = first([] as List<Atom>) // T = Atom, explicit
Option ChainingNo flattening. I actually really like this syntax for handling Casting
Structural cast ignores field names: struct Point(x:Real y:Real)
struct Coord(lat:Real lon:Real)
let c = Coord(1 2);
let p: Point = c as Point;Subject-Oriented Method ResolutionThe subject is a typed binary tree. As code composes: compose
with this; struct Point(x: @ y: @);Subject type grows: [[Arithmetic-for-Point arms] [Point-constructor prior-subject]]Method resolution for
Name collisions: disallowed in v1. Two traits with same method name = compile error. (Skip syntax What I feel like would work better is a Dojo-style wrapping of everything in a Hoon Interoplet result: Noun = hoon.some-gate(arg)
let typed: MyStruct = result as! MyStruct
Jock always lets you lose type, sort of its version of Inference Rules SummarySome initial thoughts, nothing binding here. It would be far more permissive than Hoon.
Naming
This is because otherwise you will have head tags from Hoon and external nouns which are both different as raw atoms and unparseable as snake case values. BAD! |
|
Oh, and primitive types of course.
Compound Types
|
|
Types necessary for NockApp kernel: +$ goof [mote=term =tang]
+$ wire path
+$ ovum [=wire =input]
+$ crud [=goof =input]
+$ input [eny=@ our=@ux now=@da cause=*] |
This adds support for several new types and type system components. It breaks compatibility with Jock Alpha from June 2025.