]> Git — Sourcephile - haskell/symantic-base.git/blob - src/Symantic/Dityped/Composable.hs
add Symantic.Typed
[haskell/symantic-base.git] / src / Symantic / Dityped / Composable.hs
1 module Symantic.Dityped.Composable where
2
3 import Symantic.Dityped.Transformable
4
5 -- * Class 'Composable'
6 class Composable repr where
7 (<.>) :: repr a b -> repr b c -> repr a c
8 (<.>) = lift2 (<.>)
9 default (<.>) ::
10 Liftable2 repr => Composable (Unlifted repr) =>
11 repr a b -> repr b c -> repr a c
12 infixr 4 <.>
13
14 -- * Class 'Voidable'
15 class Voidable repr where
16 default void :: Liftable1 repr => Voidable (Unlifted repr) =>
17 a -> repr (a -> b) k -> repr b k
18 void :: a -> repr (a -> b) k -> repr b k
19 void a = lift1 (void a)
20
21 -- ** Type 'IdentityTrans'
22 -- | A 'Transformable' that does nothing.
23 newtype IdentityTrans repr a k
24 = IdentityTrans
25 { unIdentityTrans :: repr a k }
26 type instance Unlifted (IdentityTrans repr) = repr
27 instance Transformable (IdentityTrans repr) repr where
28 trans = unIdentityTrans
29 instance Transformable repr (IdentityTrans repr) where
30 trans = IdentityTrans
31
32 -- * Class 'Dimapable'
33 class Dimapable repr where
34 dimap :: (a->b) -> (b->a) -> repr (a->k) k -> repr (b->k) k
35 dimap a2b b2a = lift1 (dimap a2b b2a)
36 default dimap :: Liftable1 repr => Dimapable (Unlifted repr) =>
37 (a->b) -> (b->a) -> repr (a->k) k -> repr (b->k) k