Hacker News new | past | comments | ask | show | jobs | submit login

Minor nitpick: Using pattern matching instead of `if xs == []` is not just to make code prettier and cleaner.

First of all, you should be using the `null` function instead of `== xs` because the `==` operator only works if your list contents are Eq-able.

But the most important thing is that pattern matching is more type safe. If you use `head` and `tail` you, as a programmer, need to make sure that you only call them on a non-empty lists or else you get an error. On the other hand, if you use pattern matching the compiler helps you make sure that you always covered all the possible cases (empty vs non-empty) and you never need to worry about calling the unsafe head and tail functions.




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

Search: