mirror of
https://github.com/Jaxan/ons-hs.git
synced 2025-04-27 14:47:45 +02:00
36 lines
791 B
Haskell
36 lines
791 B
Haskell
module Support.OrdList where
|
|
|
|
import qualified Data.List as List
|
|
import qualified Data.List.Ordered as OrdList
|
|
|
|
import Support.Rat
|
|
|
|
-- always sorted
|
|
newtype Support = Support { unSupport :: [Rat] }
|
|
deriving (Show, Eq, Ord)
|
|
|
|
size :: Support -> Int
|
|
size = List.length . unSupport
|
|
|
|
null :: Support -> Bool
|
|
null = List.null . unSupport
|
|
|
|
min :: Support -> Rat
|
|
min = List.head . unSupport
|
|
|
|
empty :: Support
|
|
empty = Support []
|
|
|
|
union :: Support -> Support -> Support
|
|
union (Support x) (Support y) = Support (OrdList.union x y)
|
|
|
|
singleton :: Rat -> Support
|
|
singleton r = Support [r]
|
|
|
|
toList :: Support -> [Rat]
|
|
toList = unSupport
|
|
|
|
fromList, fromAscList, fromDistinctAscList :: [Rat] -> Support
|
|
fromList = Support . OrdList.nubSort
|
|
fromAscList = Support . OrdList.nub
|
|
fromDistinctAscList = Support
|