Quantcast
Channel: Implementation of null function - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Implementation of null function

$
0
0

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.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>