4 ms·
Nice article. I thought it was going to be superficial and rehashing common ideas but the author covers a lot of ground and languages in this overview. Of all
by zak_mc_kracken 12y ago
Nice article. I thought it was going to be superficial and rehashing common ideas but the author covers a lot of ground and languages in this overview.
Of all the languages I've encountered with null/Option/Optional/Maybe in, the one I think is the most interesting is Ceylon.
Ceylon supports sum types, so you can say that a type is "Account" (non nullable) or "Account|Null" (which can be abbreviated to "Account?").
The compiler will not let you dereference a nullable type, you will have to switch/type cast it first:
Account? account = ...
if (exists account) {
// account has type Account, safe to dereference
} else {
// account has type Null, can't dereference
}
http://ceylon-lang.org/ http://ceylon-lang.org/
- zeckalpha 12y agoThis is essentially how it is in Haskell, Scala, Swift, etc.
- zak_mc_kracken 12y agoNot really. Haskell and Scala use Maybe/Option, which are monads enabling the composition of operations, even in the absence of values. This leads to a more powerful abstraction (composition) at the expense of heavier syntax and the necessity of libraries that are monad aware. Ceylon's approach is more of a middle ground with limited composability but straightforward syntax and a much simpler type system.
- theseoafs 12y agoI'm not sure what this means. In haskell you are free to use monads "the Ceylon way" if that's what you want to do; there is no reason you'd have to leverage the composability of monads if you don't want its added convenience. There is no added monadic overhead if you don't use Maybes in that way.
- wtetzner 12y agoNo, in Haskell and Scala Maybe and Option are sum types. There also happen to be monad operations defined on those types, but you don't have to use them.