Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nullable types in C#

"The predefined unary and binary operators and any user-defined operators that exist for value types may also be used by nullable types. These operators produce a null value if the operands are null; otherwise, the operator uses the contained value to calculate the result."

http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx

They are useful to avoid repeated null checking.

This can be modeled as a Monad with a notion of "failure". In Haskell that would be the Maybe monad. You would have to "lift" the arithmetic functions into it and work with "Maybe Int" values instead of "Int" values.

An if we swapped the Maybe monad with the List (nondeterminism) monad, we could work with list of values and obtain a list of results for all possible combinations (instead of just one result or failure.)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: