{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Set.Ordered.Instances
( OSetL(..)
, OSetR(..)
, singletonL
, singletonR
) where
import Data.Data (Data)
import Data.Foldable (Foldable(..))
import Data.Monoid (Monoid(..))
import Data.Semigroup (Semigroup(..))
import Data.Set.Ordered ((<>|), (|<>), OSet)
import qualified Data.Set.Ordered as OSet (empty, singleton)
import Prelude ((.), Eq, Ord, Show(..))
newtype OSetL a = OSetL
{ unOSetL :: OSet a
} deriving (Data, Eq, Ord)
singletonL ::
a
-> OSetL a
singletonL = OSetL . OSet.singleton
instance Show a => Show (OSetL a) where
show (OSetL o) = show o
instance Foldable OSetL where
foldMap f (OSetL o) = foldMap f o
instance Ord a => Semigroup (OSetL a) where
(OSetL as) <> (OSetL bs) = OSetL (as |<> bs)
instance Ord a => Monoid (OSetL a) where
mempty = OSetL OSet.empty
newtype OSetR a = OSetR
{ unOSetR :: OSet a
} deriving (Data, Eq, Ord)
singletonR ::
a
-> OSetR a
singletonR = OSetR . OSet.singleton
instance Show a => Show (OSetR a) where
show (OSetR o) = show o
instance Foldable OSetR where
foldMap f (OSetR o) = foldMap f o
instance Ord a => Semigroup (OSetR a) where
(OSetR as) <> (OSetR bs) = OSetR (as <>| bs)
instance Ord a => Monoid (OSetR a) where
mempty = OSetR OSet.empty