Ad
Algorithms
Logic

Removed unsafe use of head and tail. However, nub has a runtime complexity of O(n^2). That would make this function very inefficient for large lists...

Code
Diff
  • module AllEqual where
    import Data.List
    
    allEqual :: [Int] -> Bool 
    allEqual xs = length (nub xs) <= 1
    • module AllEqual where
    • import Data.List
    • allEqual :: [Int] -> Bool
    • allEqual xs = and $ map (== head xs) (tail xs)
    • allEqual xs = length (nub xs) <= 1