Fuck nil, maybe is much better
Fuck nil, maybe is much better
func foo(): number|nil => ...
const x = foo()
const y = x + 2 // compile error
const z = if (x != nil) { x + 2 } else { nil }
At that point the difference compared with maybe is mostly superficial func foo(): Maybe<number> => ...
x = foo()
y = fmap someOtherFunction x
instead of the more verbose
y = if (x == nil) { nil } else { someOtherFunction x }However, I want to avoid getting too deep into FP-land. The hope is for Bagel to be familiar and comfortable to existing JavaScript devs, where they can benefit from a degree of purity while being able to understand or at least guess at the meaning of a given construct in front of them based on their prior experience. To that end, I think terms like "either" will be unfamiliar, and I also think situations like (Just (Just X)) will create a lot more confusion than utility. I'm struggling to think of a useful case for that myself (I'm sure they exist, but the point remains).
I'm thinking about the teams I've worked with, and I'm thinking about what would most effectively empower them to benefit from this "stateless subset" paradigm. A guiding principle is that I want Bagel to be a language that introduces some idealism into a pragmatic context, not one that's idealistic to the detriment of usability
const z = if (x != nil) { x + 2 } // comes out to number|nil
So that's less verbose and may be acceptable as-is. You also shouldn't need to chain the syntax for multiple values: const z = if (x != nil && y != nil && z != nil) {
x + y + z
}
There may also be room to make the () optional like Rust does, or maybe just dropping the {} would be better. I'll have to see how each affects parsing and readability