2 ms·
Ok, I misunderstood then. I thought it would subtly return no value instead of a value, and you'd only discover this at run time. That would be bug prone. If it
by wladimir 14y ago
Ok, I misunderstood then. I thought it would subtly return no value instead of a value, and you'd only discover this at run time. That would be bug prone. If it simply generates a compilation error, no problem.
- danieldk 14y agoThe thing is that in a safe language, a value always evaluates to a value of the type of the expression[1]. E.g. in Haskell, if a function returns a list: foo :: Int -> [a] It should always evaluate to a list. There is no such thing as a null pointer. The only thing that comes close to a nullable type is an option type such as Maybe: data Maybe a = Just a | Nothing The function bar :: Int -> Maybe [a] can either evaluate to a Just [a] or Nothing. [1] Actually, I lied a bit, since there is bottom: http://www.haskell.org/haskellwiki/Bottom http://www.haskell.org/haskellwiki/Bottom But bottom does not fullfil the same role as, say null pointers.