Created
November 22, 2015 08:31
-
-
Save fthomas/05480c0b124108568663 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
isSorted : Ord a => List a -> Bool | |
isSorted [] = True | |
isSorted [x] = True | |
isSorted (x :: t @ (y :: ys)) = x <= y && isSorted t | |
minElem : Ord a => (l : List a) -> { auto p : isSorted l = True } -> Maybe a | |
minElem l = head' l | |
prove : Ord a => (l : List a) -> Maybe (isSorted l = True) | |
prove [] = Just $ Refl | |
prove [x] = Just $ Refl | |
prove (x :: y :: ys) with (x <= y) | |
| True = prove (y :: ys) | |
| False = Nothing | |
main : IO () | |
main = do | |
line <- getLine | |
let list = map (cast { to = Integer }) $ words line | |
case prove list of | |
Just _ => printLn $ minElem list | |
Nothing => printLn "input list is not sorted" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment