4 ms·
The proc/func dichotomy is a really interesting idea! I'll be interested to see how that plays out. How do you see those fitting in as class/object members? Pre
by b3morales 5y ago
The proc/func dichotomy is a really interesting idea! I'll be interested to see how that plays out. How do you see those fitting in as class/object members? Presumably both types would have to be able to access instance fields. Any other restrictions that crop up?
Or is the "possibly nominal types" bullet an indication that you don't plan to have things that can have members at all?
- brundolf 5y agoI plan on having classes, and I plan for classes to support both functions and procedures as members. If you think about it, classes already have "pure functions of themselves" in the form of getters! JS/TS has just never been able to enforce that purity before, which meant that you could technically access a property and have a side-effect: class Foo { get prop1() { this.state = Math.random(); return this.state; } } console.log(myFoo.prop1) console.log(myFoo.prop1) // different! So I think the func/proc distinction will line up really nicely with classes as containers of state. And, as in other cases, pure functions will be able to access properties and call pure functions on class instances, just not call their procedures Other things I'm going to try out with classes are getting rid of inheritance, and adding a publicly-readable-but-privately-writable access modifier for properties
- kybernetikos 5y agoOne of the fun possibilities is that funcs could be safely turned into a serialized version for sending over the wire etc. Will bagel have a json equivalent?
- brundolf 5y agoBagel values will fundamentally be JavaScript values, so the same subset of them will naturally translate to JSON With that said I hope to give stronger typing to what's allowed to be converted to JSON, since JavaScript's serialization will happily eat up class instances (losing class information), dates (silently converting them to strings), undefined, etc.
- brundolf 5y agoEdit: Just noticed you said funcs and not func results This isn't really true, since they'll still capture their closures and will definitely be able to reference other constructs like classes, etc
- kybernetikos 5y agoChanging mutable state you've closed over is a side effect, so from your description I assumed that wouldn't be allowed in a function. Or are you talking about reading mutable state you've closed over where you're still a pure function (just with hidden arguments) but the environment might change and you can't send that over the wire.
- brundolf 5y agoThat's what I mean. Functions can't mutate anything, period- the assignment operator won't even parse, and calls to procedures are forbidden. But they can still close over state that is mutable one other contexts The full implications of allowing this in closures have yet to be explored and I still need to make sure they won't break the guarantees I'm wanting to offer