{-# LANGUAGE MultiParamTypeClasses #-} module Language.LOL.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 a representation to the transformer's representation. trans_lift :: repr a -> trans repr a -- | Unlift a representation from the transformer's representation. trans_apply :: trans repr a -> repr a -- | Convenient method to define the identity transformation for a unary function. 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 function. 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)