{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances,
FlexibleContexts, PolyKinds, TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Profunctor.Product.Default
( module Data.Profunctor.Product.Default
, module Data.Profunctor.Product.Default.Class
) where
import Control.Applicative (Const (Const))
import Data.Functor.Identity (Identity (Identity))
import Data.Profunctor (Profunctor, dimap)
import Data.Profunctor.Product
import Data.Tagged (Tagged (Tagged))
import Data.Profunctor.Product.Default.Class
import Data.Profunctor.Product.Tuples.TH (mkDefaultNs, maxTupleSize)
instance (Profunctor p, Default p a b) => Default p (Identity a) (Identity b)
where
def :: p (Identity a) (Identity b)
def = (Identity a -> a)
-> (b -> Identity b) -> p a b -> p (Identity a) (Identity b)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (\(Identity a
a) -> a
a) b -> Identity b
forall a. a -> Identity a
Identity p a b
forall (p :: * -> * -> *) a b. Default p a b => p a b
def
instance (Profunctor p, Default p a b) => Default p (Const a c) (Const b c')
where
def :: p (Const a c) (Const b c')
def = (Const a c -> a)
-> (b -> Const b c') -> p a b -> p (Const a c) (Const b c')
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (\(Const a
a) -> a
a) b -> Const b c'
forall k a (b :: k). a -> Const a b
Const p a b
forall (p :: * -> * -> *) a b. Default p a b => p a b
def
instance (Profunctor p, Default p a b) => Default p (Tagged s a) (Tagged s' b)
where
def :: p (Tagged s a) (Tagged s' b)
def = (Tagged s a -> a)
-> (b -> Tagged s' b) -> p a b -> p (Tagged s a) (Tagged s' b)
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (\(Tagged a
a) -> a
a) b -> Tagged s' b
forall k (s :: k) b. b -> Tagged s b
Tagged p a b
forall (p :: * -> * -> *) a b. Default p a b => p a b
def