Re:Such a Little Thing: The Semicolon in Rust
by wladimir on Friday October 19, 2012 @05:11AM
(#4672801)
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.
[ Parent
| on HN ]
Re:Such a Little Thing: The Semicolon in Rust
by danieldk on Friday October 19, 2012 @08:06AM
(#4673125)
The 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 But bottom does not fullfil the same role as, say null pointers.