Created
November 1, 2018 18:40
-
-
Save chessai/f20deb39b0a1a83949201cc6c2ab94b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Ordered a = Empty | Decreasing a | Increasing a | |
inc :: Ordered a -> Bool | |
inc (Decreasing _) = False | |
inc _ = True | |
dec :: Ordered a -> Bool | |
dec (Increasing _) = False | |
dec _ = True | |
increasing :: (Foldable t, Ord a) => t a -> Bool | |
increasing = inc . foldl' go Empty where | |
go Empty y = Increasing y | |
go (Decreasing x) _ = Decreasing x | |
go (Increasing x) y | |
| x <= y = Increasing y | |
| otherwise = Decreasing y | |
decreasing :: (Foldable t, Ord a) => t a -> Bool | |
decreasing = dec . foldl' go Empty where | |
go Empty y = Decreasing y | |
go (Increasing x) _ = Increasing x | |
go (Decreasing x) y | |
| x >= y = Decreasing y | |
| otherwise = Increasing y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment