module Data.Wrapped where
import Control.Applicative (Applicative(..))
import Data.Default
data Wrapped a b = Wrap a b
defWrap :: Default a => b -> Wrapped a b
defWrap = Wrap def
unwrapF :: Wrapped a b -> a
unwrapF (Wrap x _) = x
unwrapR :: Wrapped a b -> b
unwrapR (Wrap _ y) = y
unwrap :: Wrapped a b -> b
unwrap = unwrapR
wrappedAp :: Wrapped (t -> a) b -> t -> Wrapped a b
wrappedAp (Wrap f y) x = Wrap (f x) y
instance Eq b => Eq (Wrapped a b) where
(==) (Wrap x y) (Wrap z w) = y == w
instance Ord b => Ord (Wrapped a b) where
compare (Wrap x y) (Wrap z w) = compare y w
instance (Default a, Enum b) => Enum (Wrapped a b) where
toEnum n = defWrap (toEnum n)
fromEnum (Wrap _ y) = fromEnum y
instance (Default a, Bounded b) => Bounded (Wrapped a b) where
minBound = defWrap minBound
maxBound = defWrap maxBound
instance Functor (Wrapped a) where
fmap :: (a1 -> b) -> Wrapped a a1 -> Wrapped a b
fmap f (Wrap t x) = Wrap t (f x)
instance Default a => Applicative (Wrapped a) where
pure :: a1 -> Wrapped a a1
pure = defWrap
(<*>) :: Wrapped a (a1 -> b) -> Wrapped a a1 -> Wrapped a b
(<*>) (Wrap _ f) (Wrap t x) = Wrap t (f x)
instance (Default a, Default b) => Default (Wrapped a b) where
def = defWrap def
instance Show b => Show (Wrapped a b) where
showsPrec n (Wrap _ y) = showsPrec n y
show (Wrap _ y) = show y