The benefits of the language outweigh the minor inconvenience.
10,762 karma · joined February 10, 2010
The benefits of the language outweigh the minor inconvenience.
const intf = interface.implBy(implementation)
This makes it possible to write an interface against any implementation objects. E.g. I can write an interface against the standard hashmap's get() and put() methods. Why would I do that? Let's say I have my custom hashmap with get() and put(), but I want to use the standard hashmap as fallback. A common interface working against my custom hashmap and the standard hashamp is possible.I wrote a second blog for the C++ style vtable. https://williamw520.github.io/2025/07/17/memory-efficient-zi...
The first version is faster (one pointer indirection) with more memory consumed. The second version is more memory efficient sharing a single vtable for all instances, a bit slower (two pointer indirections).
For example for a type system,
let a: Int // this says 'a' has the type Int
a = 5 // compiler allows, as both 'a' and 5 are of Int.
a = 5.1 // disallowed, as 'a' and 5.1 are of different types.
Similarly for example for an effect system, let a: Int
let b: Int!Div0 // 'b' is of type Int and the Div0 effect.
let c: Int
...
a = 1 / c // disallowed, as '/' causes the Div0 effect which 'a' not supported
b = 1 / c // allowed, as both '/' and 'b' support the Div0 effect.
The effect annotations can be applied to a function just like the type annotations. Callers of the function need to anticipate (or handle) the effect. E.g. let's say the above code is wrapped in a function 'compute1(..) Int!Div0', a caller calling it can do. compute1(..) on effect(Div0) {
// handle the Div0 effect.
} class Maybe {
value: int;
static wrap(v: int) {
return new Maybe { value = v }
}
// map() applies fn on the unwrapped value. fn returns a Maybe.
map(fn: (x: int) => Maybe) {
return this.value == null ? Maybe.wrap(null) : fn(this.value);
}
}
Here Maybe.wrap() is "unit" and Maybe.map() is "bind" in Haskell lingo. The whole thing is a monad. You can chain call with it. Maybe.wrap(5)
.map(x => Maybe.wrap(x + 1))
.map(x => Maybe.wrap(x * 2))Zig.day looks like a wonderful way to do laid back hackathons. Looking forward to one coming up.
Does the new change make it easier to store reader/writer in a struct?
It’s similar for monad. If you can provide a unit constructor to turn an object value into a monad value and a “map” operation that unwraps a monad value, applies a function to it, and wraps the result, you have monadized the object type. Your objects can participate in any algorithm operates on monads.
The monad algorithms are the same. The only things different are the unit constructor and the mapping function.
Also the radiated heat from the Sun won't have much effect if the heat sink panels are facing perpendicular to the sun with two sides pointing sideway to deep space to radiate away the heat.
https://transparentcalifornia.com/salaries/search/?q=Joseph+...
Teaching is the best way to learn. I found that out when I started tutoring classmates for math in high school.
Same thing with writing a book. Something about learning a subject and turning around to speak/write out about it that really crystallizes the in-depth understanding beneath the surface.