{-# LANGUAGE MultiParamTypeClasses #-} 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 trans repr where -- | Lift an interpreter to the transformer's. trans_lift :: repr a -> trans repr a -- | Unlift an interpreter from the transformer's. trans_apply :: trans repr a -> repr a -- | Convenient method to define the identity transformation for a unary symantic method. trans_map1 :: (repr a -> repr b) -> (trans repr a -> trans 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) -> (trans repr a -> trans repr b -> trans 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) -> (trans repr a -> trans repr b -> trans repr c -> trans repr d) trans_map3 f e1 e2 e3 = trans_lift $ f (trans_apply e1) (trans_apply e2) (trans_apply e3)