Saturday, 4 June 2016

Haskell: Return True, if the list is empty (or) firstElement of the list is empty, else False


CheckList.hs
isListOrFirstEmpty :: [[a]] -> Bool
isListOrFirstEmpty xs = 
    if (null xs) 
        then 
            True 
    else if (null (head xs))
        then
            True
    else
        False

*Main> :load CheckList.hs 
[1 of 1] Compiling Main             ( CheckList.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> isListOrFirstEmpty []
True
*Main> isListOrFirstEmpty ["abc", ""]
False
*Main> isListOrFirstEmpty ["", "abc"]
True


Previous                                                 Next                                                 Home

No comments:

Post a Comment