{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} module Language.Symantic.Trans.Common where -- | -- * 'trans_lift' is generally not /surjective/ -- * 'trans_apply' is not /injective/ -- * 'trans_apply' . 'trans_lift' == 'id' -- * 'trans_lift' . 'trans_apply' /= 'id' -- -- NOTE: @DefaultSignatures@ can be used -- when declaring a symantic type class -- to provide default definition of the methods: -- implementing their identity transformation -- in order to avoid boilerplate code -- when writting 'Trans' instances which -- do not need to alterate those methods. class Trans t repr where -- | Lift an interpreter to the transformer's. trans_lift :: repr a -> t repr a -- | Unlift an interpreter from the transformer's. trans_apply :: t repr a -> repr a -- | Convenient method to define the identity transformation for a unary symantic method. trans_map1 :: (repr a -> repr b) -> (t repr a -> t repr b) trans_map1 f = trans_lift . f . trans_apply -- | Convenient method to define the identity transformation for a binary symantic method. trans_map2 :: (repr a -> repr b -> repr c) -> (t repr a -> t repr b -> t repr c) trans_map2 f e1 e2 = trans_lift (trans_apply e1 `f` trans_apply e2) -- | Convenient method to define the identity transformation for a terary symantic method. trans_map3 :: (repr a -> repr b -> repr c -> repr d) -> (t repr a -> t repr b -> t repr c -> t repr d) trans_map3 f e1 e2 e3 = trans_lift $ f (trans_apply e1) (trans_apply e2) (trans_apply e3) -- | Closed type family extracting the representation -- upon which a transformer is applied. -- -- This is useful to write default associated types in symantics. type family Repr_of_Trans (repr :: * -> *) :: (* -> *) where Repr_of_Trans (t repr) = repr