]> Git — Sourcephile - haskell/symantic.git/blob - symantic/Language/Symantic/Transforming/Trans.hs
Add Trans defaults.
[haskell/symantic.git] / symantic / Language / Symantic / Transforming / Trans.hs
1 module Language.Symantic.Transforming.Trans where
2
3 -- |
4 -- * 'trans' is generally not /surjective/
5 -- * 'unTrans' is not /injective/
6 -- * 'unTrans' . 'trans' == 'id'
7 -- * 'trans' . 'unTrans' /= 'id'
8 --
9 -- NOTE: @DefaultSignatures@ can be used
10 -- when declaring a symantic type class
11 -- to provide default definition of the methods:
12 -- implementing their identity transformation
13 -- in order to avoid boilerplate code
14 -- when writting 'Trans' instances which
15 -- do not need to alterate those methods.
16 class Trans tr where
17 -- | Return the underlying @tr@ of the transformer.
18 type UnT tr :: * -> *
19
20 -- | Lift a tr to the transformer's.
21 trans :: UnT tr a -> tr a
22 -- | Unlift a tr from the transformer's.
23 unTrans :: tr a -> UnT tr a
24
25 -- | Identity transformation for a unary symantic method.
26 trans1 :: (UnT tr a -> UnT tr b) -> (tr a -> tr b)
27 trans1 f = trans . f . unTrans
28
29 -- | Identity transformation for a binary symantic method.
30 trans2
31 :: (UnT tr a -> UnT tr b -> UnT tr c)
32 -> (tr a -> tr b -> tr c)
33 trans2 f t1 t2 = trans $ f (unTrans t1) (unTrans t2)
34
35 -- | Identity transformation for a ternary symantic method.
36 trans3
37 :: (UnT tr a -> UnT tr b -> UnT tr c -> UnT tr d)
38 -> (tr a -> tr b -> tr c -> tr d)
39 trans3 f t1 t2 t3 = trans $ f (unTrans t1) (unTrans t2) (unTrans t3)