I have to learn Haskell for university and therefor I'm using learnyouahaskell.com for the beginning.
I always used imperative languages so I decided to practice Haskell by coding a lot more than I would for other languages.
I started to implement several functions to work with lists such as head
, tail
, init
,...
At some point I looked up the implementations of these functions to compare to mine and I stumbled upon the null function defined in List.lhs
.
null's implementation:
-- | Test whether a list is empty.null :: [a] -> Boolnull [] = Truenull (_:_) = False
my implementation:
mNull :: [a] -> BoolmNull [] = TruemNull _ = False
I know there are no stupid questions even for such simple questions :)
So my question is why the original implementation uses (_:_)
instead of just _
?
Is there any advantage in using (_:_)
or are there any edge cases I don't know of?
I can't really imagine any advantage because _
catches everything.