Monday 6 June 2016

Haskell: Check whether list is empty (or) not


listUtil.hs
isListEmpty :: [a] -> Bool
isListEmpty [] = True
isListEmpty _ = False

*Main> :load listUtil.hs
[1 of 1] Compiling Main             ( listUtil.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> isListEmpty []
True
*Main> isListEmpty [1, 2, 3]
False
*Main> isListEmpty [1..]
False
*Main> isListEmpty ""
True
*Main> 


Previous                                                 Next                                                 Home

No comments:

Post a Comment