module Data.MonoTraversable.Container where
import Data.Foldable
import Data.MonoTraversable
import Text.Read
data Container xs a b where
Container :: (a ~ b) => xs -> Container xs a b
getContainer :: Container xs a b -> xs
getContainer (Container xs) = xs
instance Eq xs => Eq (Container xs a b) where
Container x == Container y = x == y
instance Ord xs => Ord (Container xs a b) where
compare (Container x) (Container y) = compare x y
Container x < Container y = x < y
Container x >= Container y = x >= y
Container x > Container y = x > y
Container x <= Container y = x <= y
max (Container x) (Container y) = Container (max x y)
min (Container x) (Container y) = Container (min x y)
instance Show xs => Show (Container xs a b) where
showsPrec d (Container a) =
showParen (d >= 11)
$ showString "Container "
. showsPrec 11 a
instance (Read xs, a ~ b) => Read (Container xs a b) where
readPrec = parens $ prec 10 $ do
Ident "Container" <- lexP
Container <$> step (readS_to_Prec readsPrec)
instance (MonoFoldable xs, element ~ Element xs) =>
Foldable (Container xs element) where
foldr f b (Container xs) = ofoldr f b xs
foldMap f (Container xs) = ofoldMap f xs
foldl' f b (Container xs) = ofoldl' f b xs
toList (Container xs) = otoList xs
null (Container xs) = onull xs
length (Container xs) = olength xs
foldr1 f (Container xs) = ofoldr1Ex f xs
elem x (Container xs) = oelem x xs
maximum (Container xs) = maximumEx xs
minimum (Container xs) = minimumEx xs
sum (Container xs) = osum xs
product (Container xs) = oproduct xs