lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Swift optionals are sort-of an implementation of the Maybe-monad.

An alternative to exceptions would be a more general version of NaN which is in itself essentially a form of the Maybe monad. If one doesn't want to introduce a new value, then use nil. nil[ key ] yields nil. Calling nil yields nil. Etc. Or introduce a new error type that can include more information and use this as a result. I'm not sure what should happen in error cases that don't return values such as assignments to entries in values that aren't tables.


> On Jan 11, 2015, at 2:39 AM, Tim Hill <> wrote:
> For another interesting approach, see the use of optionals in Swift (which I suspect are not original to Swift, but are reasonably well thought out).