-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathListQSort.hs
39 lines (25 loc) · 995 Bytes
/
ListQSort.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module ListQSort () where
import Language.Haskell.Liquid.Prelude
app k [] ys = k:ys
app k (x:xs) ys = x:(app k xs ys)
takeL x [] = []
takeL x (y:ys) = if (y<x) then y:(takeL x ys) else takeL x ys
takeGE x [] = []
takeGE x (y:ys) = if (y>=x) then y:(takeGE x ys) else takeGE x ys
{-@ quicksort :: (Ord a) => xs:[a] -> [a]<{\fld v -> (v >= fld)}> @-}
quicksort [] = []
quicksort (x:xs) = app x xsle xsge
where xsle = quicksort (takeL x xs)
xsge = quicksort (takeGE x xs)
{-@ qsort :: (Ord a) => xs:[a] -> [a]<{\fld v -> (v >= fld)}> @-}
qsort [] = []
qsort (x:xs) = app x (qsort [y | y <- xs, y < x]) (qsort [z | z <- xs, z >= x])
-------------------------------------------------------------------------------
chk [] = liquidAssertB True
chk (x1:xs) = case xs of
[] -> liquidAssertB True
x2:xs2 -> liquidAssertB (x1 <= x2) && chk xs
prop0 = chk bar
where
rlist = map choose [1 .. 10]
bar = quicksort rlist