]> Git — Sourcephile - haskell/symantic.git/blob - symantic/Language/Symantic/Transforming/Trans.hs
Split into symantic{,-grammar,-lib}.
[haskell/symantic.git] / symantic / Language / Symantic / Transforming / Trans.hs
1 module Language.Symantic.Transforming.Trans where
2
3 -- |
4 -- * 'trans_lift' is generally not /surjective/
5 -- * 'trans_apply' is not /injective/
6 -- * 'trans_apply' . 'trans_lift' == 'id'
7 -- * 'trans_lift' . 'trans_apply' /= '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 t term where
17 -- | Lift a term to the transformer's.
18 trans_lift :: term a -> t term a
19 -- | Unlift a term from the transformer's.
20 trans_apply :: t term a -> term a
21
22 -- | Convenient method to define the identity transformation for a unary symantic method.
23 trans_map1 :: (term a -> term b) -> (t term a -> t term b)
24 trans_map1 f = trans_lift . f . trans_apply
25
26 -- | Convenient method to define the identity transformation for a binary symantic method.
27 trans_map2
28 :: (term a -> term b -> term c)
29 -> (t term a -> t term b -> t term c)
30 trans_map2 f e1 e2 = trans_lift (trans_apply e1 `f` trans_apply e2)
31
32 -- | Convenient method to define the identity transformation for a ternary symantic method.
33 trans_map3
34 :: (term a -> term b -> term c -> term d)
35 -> (t term a -> t term b -> t term c -> t term d)
36 trans_map3 f e1 e2 e3 = trans_lift $ f (trans_apply e1) (trans_apply e2) (trans_apply e3)
37
38 -- | Closed type family extracting the term
39 -- upon which a transformer is applied.
40 --
41 -- This is useful to write default associated types in symantics.
42 type family Term_of_Trans (term :: * -> *) :: (* -> *) where
43 Term_of_Trans (t term) = term