Skip to content

Instantly share code, notes, and snippets.

@kaveet
Last active December 9, 2022 07:31
Show Gist options
  • Save kaveet/b77f2f3add61d9c3afdb6852b7f36b03 to your computer and use it in GitHub Desktop.
Save kaveet/b77f2f3add61d9c3afdb6852b7f36b03 to your computer and use it in GitHub Desktop.
Check if list is sorted in Haskell
module Sorted where
sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:y:xs) = if x <= y then sorted (y:xs) else False
@robbie01
Copy link

sorted xs = and $ zipWith (<=) xs (tail xs)

Haskell is so cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment