]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Trans/Common.hs
init
[haskell/symantic.git] / Language / Symantic / Trans / Common.hs
1 {-# LANGUAGE MultiParamTypeClasses #-}
2 module Language.Symantic.Trans.Common where
3
4 -- |
5 -- * 'trans_lift' is generally not /surjective/
6 -- * 'trans_apply' is not /injective/
7 -- * 'trans_apply' . 'trans_lift' == 'id'
8 -- * 'trans_lift' . 'trans_apply' /= 'id'
9 --
10 -- NOTE: @DefaultSignatures@ can be used
11 -- when declaring a symantic type class
12 -- to provide default definition of the methods:
13 -- implementing their identity transformation
14 -- in order to avoid boilerplate code
15 -- when writting 'Trans' instances which
16 -- do not need to alterate those methods.
17 class Trans t repr where
18 -- | Lift an interpreter to the transformer's.
19 trans_lift :: repr a -> t repr a
20 -- | Unlift an interpreter from the transformer's.
21 trans_apply :: t repr a -> repr a
22
23 -- | Convenient method to define the identity transformation for a unary symantic method.
24 trans_map1 :: (repr a -> repr b) -> (t repr a -> t repr b)
25 trans_map1 f = trans_lift . f . trans_apply
26
27 -- | Convenient method to define the identity transformation for a binary symantic method.
28 trans_map2
29 :: (repr a -> repr b -> repr c)
30 -> (t repr a -> t repr b -> t repr c)
31 trans_map2 f e1 e2 = trans_lift (trans_apply e1 `f` trans_apply e2)
32
33 -- | Convenient method to define the identity transformation for a terary symantic method.
34 trans_map3
35 :: (repr a -> repr b -> repr c -> repr d)
36 -> (t repr a -> t repr b -> t repr c -> t repr d)
37 trans_map3 f e1 e2 e3 = trans_lift $ f (trans_apply e1) (trans_apply e2) (trans_apply e3)