module Data.Append where import qualified Data.NonEmpty.Class as C import Control.Applicative (liftA2) import Control.DeepSeq (NFData, rnf, ) import Data.Traversable (Traversable, traverse) import Data.Foldable (Foldable, foldMap) import Data.Monoid (mappend) import Prelude hiding (fst, snd) data T f g a = Cons { forall (f :: * -> *) (g :: * -> *) a. T f g a -> f a fst :: f a, forall (f :: * -> *) (g :: * -> *) a. T f g a -> g a snd :: g a } instance (Functor f, Functor g) => Functor (T f g) where fmap :: forall a b. (a -> b) -> T f g a -> T f g b fmap a -> b f (Cons f a xs g a ys) = forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> T f g a Cons (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> b f f a xs) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> b f g a ys) instance (Foldable f, Foldable g) => Foldable (T f g) where foldMap :: forall m a. Monoid m => (a -> m) -> T f g a -> m foldMap a -> m f (Cons f a xs g a ys) = forall a. Monoid a => a -> a -> a mappend (forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap a -> m f f a xs) (forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap a -> m f g a ys) instance (Traversable f, Traversable g) => Traversable (T f g) where traverse :: forall (f :: * -> *) a b. Applicative f => (a -> f b) -> T f g a -> f (T f g b) traverse a -> f b f (Cons f a xs g a ys) = forall (f :: * -> *) a b c. Applicative f => (a -> b -> c) -> f a -> f b -> f c liftA2 forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> T f g a Cons (forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) traverse a -> f b f f a xs) (forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) traverse a -> f b f g a ys) instance (C.NFData f, C.NFData g) => C.NFData (T f g) where rnf :: forall a. NFData a => T f g a -> () rnf (Cons f a f g a g) = forall a. NFData a => a -> () rnf (forall (f :: * -> *) a. (NFData f, NFData a) => f a -> () C.rnf f a f, forall (f :: * -> *) a. (NFData f, NFData a) => f a -> () C.rnf g a g) instance (C.NFData f, C.NFData g, NFData a) => NFData (T f g a) where rnf :: T f g a -> () rnf = forall (f :: * -> *) a. (NFData f, NFData a) => f a -> () C.rnf