    {-# OPTIONS_GHC -fno-warn-orphans #-}

    module Data.Validity.Set where

    import Data.Containers.ListUtils
    import Data.Set (Set)
    import qualified Data.Set as S
    import Data.Validity

    -- | A 'Set' of things is valid if all the elements are valid and the 'Set' itself
    -- is valid.
    instance (Ord v, Validity v) => Validity (Set v) where
      validate :: Set v -> Validation
    validate Set v
    s =
        [Validation] -> Validation
    forall a. Monoid a => [a] -> a
    mconcat
          [ String -> Bool -> Validation
    declare String
    "The set structure is valid." (Bool -> Validation) -> Bool -> Validation
    forall a b. (a -> b) -> a -> b
    $ Set v -> Bool
    forall a. Ord a => Set a -> Bool
    S.valid Set v
    s,
            [v] -> String -> Validation
    forall a. Validity a => a -> String -> Validation
    annotate (Set v -> [v]
    forall a. Set a -> [a]
    S.toList Set v
    s) String
    "Set elements"
          ]

    distinctOrd :: (Ord a) => [a] -> Bool
    distinctOrd :: forall a. Ord a => [a] -> Bool
    distinctOrd [a]
    ls = [a] -> [a]
    forall a. Ord a => [a] -> [a]
    nubOrd [a]
    ls [a] -> [a] -> Bool
    forall a. Eq a => a -> a -> Bool
    == [a]
    ls