]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Transforming/Trans.hs
Add Typing.Family and Compiling.MonoFunctor.
[haskell/symantic.git] / Language / Symantic / Transforming / Trans.hs
1 {-# LANGUAGE MultiParamTypeClasses #-}
2 {-# LANGUAGE TypeFamilies #-}
3 module Language.Symantic.Transforming.Trans where
4
5 -- |
6 -- * 'trans_lift' is generally not /surjective/
7 -- * 'trans_apply' is not /injective/
8 -- * 'trans_apply' . 'trans_lift' == 'id'
9 -- * 'trans_lift' . 'trans_apply' /= 'id'
10 --
11 -- NOTE: @DefaultSignatures@ can be used
12 -- when declaring a symantic type class
13 -- to provide default definition of the methods:
14 -- implementing their identity transformation
15 -- in order to avoid boilerplate code
16 -- when writting 'Trans' instances which
17 -- do not need to alterate those methods.
18 class Trans t term where
19 -- | Lift a term to the transformer's.
20 trans_lift :: term a -> t term a
21 -- | Unlift a term from the transformer's.
22 trans_apply :: t term a -> term a
23
24 -- | Convenient method to define the identity transformation for a unary symantic method.
25 trans_map1 :: (term a -> term b) -> (t term a -> t term b)
26 trans_map1 f = trans_lift . f . trans_apply
27
28 -- | Convenient method to define the identity transformation for a binary symantic method.
29 trans_map2
30 :: (term a -> term b -> term c)
31 -> (t term a -> t term b -> t term c)
32 trans_map2 f e1 e2 = trans_lift (trans_apply e1 `f` trans_apply e2)
33
34 -- | Convenient method to define the identity transformation for a ternary symantic method.
35 trans_map3
36 :: (term a -> term b -> term c -> term d)
37 -> (t term a -> t term b -> t term c -> t term d)
38 trans_map3 f e1 e2 e3 = trans_lift $ f (trans_apply e1) (trans_apply e2) (trans_apply e3)
39
40 -- | Closed type family extracting the term
41 -- upon which a transformer is applied.
42 --
43 -- This is useful to write default associated types in symantics.
44 type family Term_of_Trans (term :: * -> *) :: (* -> *) where
45 Term_of_Trans (t term) = term