Skip to content

Instantly share code, notes, and snippets.

@fthomas
Created November 22, 2015 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fthomas/05480c0b124108568663 to your computer and use it in GitHub Desktop.
Save fthomas/05480c0b124108568663 to your computer and use it in GitHub Desktop.
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