-- similar to prelude-extras
module Data.Graph.Comfort.TypeConstructor (
   Wrap(Wrap, unwrap),
   ) where

import Data.Functor.Classes (Eq1(eq1), Ord1(compare1), Show1(showsPrec1))

import Data.Traversable (Traversable, traverse)
import Data.Foldable (Foldable, foldMap)


newtype Wrap f a = Wrap {unwrap :: f a}

instance (Eq1 f, Eq a) => Eq (Wrap f a) where
   Wrap x == Wrap y  =  eq1 x y

instance (Ord1 f, Ord a) => Ord (Wrap f a) where
   compare (Wrap x) (Wrap y)  =  compare1 x y

instance (Show1 f, Show a) => Show (Wrap f a) where
   showsPrec p (Wrap x)  =  showsPrec1 p x

instance Functor f => Functor (Wrap f) where
   fmap f (Wrap a) = Wrap (fmap f a)

instance Foldable f => Foldable (Wrap f) where
   foldMap f (Wrap a) = foldMap f a

instance Traversable f => Traversable (Wrap f) where
   traverse f (Wrap a) = fmap Wrap $ traverse f a