{-# LANGUAGE FlexibleInstances #-}
module Treap.Measured
( Measured (..)
) where
import Data.Functor.Identity (Identity (..))
import Data.Monoid (All (..), Any (..), Dual (..), Endo (..), First (..), Last (..), Product (..),
Sum (..))
import Data.Semigroup (Max (..), Min (..))
class Monoid m => Measured m a where
measure :: a -> m
instance Monoid a => Measured (Identity a) a where
measure = Identity
{-# INLINE measure #-}
instance Monoid a => Measured (Dual a) a where
measure = Dual
{-# INLINE measure #-}
instance Measured (Endo a) (a -> a) where
measure = Endo
{-# INLINE measure #-}
instance Num a => Measured (Sum a) a where
measure = Sum
{-# INLINE measure #-}
instance Num a => Measured (Product a) a where
measure = Product
{-# INLINE measure #-}
instance (Ord a, Bounded a) => Measured (Min a) a where
measure = Min
{-# INLINE measure #-}
instance (Ord a, Bounded a) => Measured (Max a) a where
measure = Max
{-# INLINE measure #-}
instance Measured (First a) a where
measure = First . Just
{-# INLINE measure #-}
instance Measured (Last a) a where
measure = Last . Just
{-# INLINE measure #-}
instance Measured All Bool where
measure = All
instance Measured Any Bool where
measure = Any