Monday 6 June 2016

Haskell: Check whether all the elements in the list are odd or not.

Following statement returns True, of all the elements in the list are odd numbers, else False.
allOdd list = ([] == [x | x <- list, even x])

Prelude> let allOdd list = ([] == [x | x <- list, even x])
Prelude> 
Prelude> allOdd [4, 5, 6]
False
Prelude> 
Prelude> allOdd [3, 5, 7]
True



Previous                                                 Next                                                 Home

No comments:

Post a Comment