-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPropertyQue.hs
More file actions
27 lines (21 loc) · 870 Bytes
/
PropertyQue.hs
File metadata and controls
27 lines (21 loc) · 870 Bytes
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
module PropertyQue ( PropertyQue
, emptyPQ
, isEmptyPQ
, addPQ
, remPQ ) where
newtype PropertyQue a = PropertyQue { unPropertyQue :: [a] }
emptyPQ :: PropertyQue a
emptyPQ = PropertyQue []
isEmptyPQ :: PropertyQue a -> Bool
isEmptyPQ (PropertyQue []) = True
isEmptyPQ _ = False
addPQ :: (Eq a, Ord a) => a -> PropertyQue a -> PropertyQue a
addPQ val (PropertyQue ls) = PropertyQue (insert val ls)
insert :: (Eq a, Ord a) => a -> [a] -> [a]
insert val [] = [val]
insert val (x : xs) = if x >= val
then val : x : xs
else x : insert val xs
remPQ :: (Eq a, Ord a) => PropertyQue a -> PropertyQue a
remPQ (PropertyQue []) = error "propertyque empty"
remPQ (PropertyQue xs) = PropertyQue (init xs)