Hacker News new | ask | show | jobs
by hopia 2338 days ago
Isn't that just due to `head` being a non-total function?

Nothing to do with null per se.

1 comments

Well, Haskell calls the empty list the "null" list (see List.null), so I could say that List.head crashes when it encounters a null. :P

Anyway, the real lesson is that even if your language has sane defaults that force you to check that your list isn't empty, or that your pointers aren't null, a bad library function like List.head can hide that check away from you and crash anyway, bringing you back to square one in terms of the type system preventing unexpected crashes.

The null works with cons. So it's not a proper null. A proper null should throw an exception if you try to do any operation on it.