module Cgm.Data.Structured (
Structured(..),
struct,
wrap,
unwrap,
in1,
in2,
structureMap,
deriveStructured,
module Cgm.Control.InFunctor
) where
import Cgm.Data.Structured.Derive
import Control.Arrow
import Data.Functor.Compose
import Cgm.Control.Combinators
import Cgm.Control.InFunctor
class Structured a where
type Structure a
structure :: a -> Structure a
fromStructure :: Structure a -> a
deriveStructured ''(,,)
deriveStructured ''(,,,)
deriveStructured ''(,,,,)
deriveStructured ''(,,,,,)
deriveStructured ''[]
deriveStructured ''Maybe
deriveStructured ''Bool
deriveStructured ''Ordering
deriveStructured ''Kleisli
deriveStructured ''Compose
deriveStructured ''RevFun
struct :: Structured a => Bijection' a (Structure a)
struct = uncheckedBijection structure fromStructure
unwrap :: Structured a => a -> Structure a
unwrap = structure
wrap :: Structured a => Structure a -> a
wrap = fromStructure
in1 :: (Structured a, Structured b) => (Structure a -> Structure b) -> a -> b
in1 f = wrap . f . unwrap
in2 :: (Structured a, Structured b, Structured c) => (Structure a -> Structure b -> Structure c) -> a -> b -> c
in2 f = wrap ./ dot2 f unwrap unwrap
structureMap :: (InjectionACofunctor p, Structured a) => p (Structure a) -> p a
structureMap = (`iacomap` struct)