-- |-- Module: Language.KURE.Translate -- Copyright: (c) 2006-2008 Andy Gill-- License: BSD3---- Maintainer: Andy Gill <andygill@ku.edu>-- Stability: unstable-- Portability: ghc---- 'Translate' is the main abstraction inside KURE, and represents a rewriting from a source to a target-- of a possibly different type.---- Rewrite (defined in 'Language.KURE.Rewrite') is a synonoym for a 'Translate' with the same source and target type.moduleLanguage.KURE.Translate(Translate,apply,runTranslate,transparently,translate)whereimportControl.MonadimportData.MonoidimportLanguage.KURE.RewriteMonad-- | 'Translate' is a translation or strategy that translates between @exp1@ and @exp2@, with the posiblity of failure,-- and remembers identity translations.newtypeTranslatemdecexp1exp2=Translate(exp1->RewriteMmdecexp2)-- | 'apply' directly applies a 'Translate' value to an argument.apply::(Monoiddec,Monadm)=>Translatemdecexp1exp2->exp1->RewriteMmdecexp2apply(Translatet)exp1=texp1-- | 'translate' is the standard way of building a 'Translate', where if the translation is successful it -- is automatically marked as a non-identity translation. ---- Note: @translate $ \\ e -> return e@ /is not/ an identity rewrite, but a succesful rewrite that-- returns its provided argument. translate::(Monoiddec,Monadm)=>(exp1->RewriteMmdecexp2)->Translatemdecexp1exp2translatef=Translate$\e->markM$fe-- | 'transparently' marks a 'translate' (or 'rewrite') as transparent, that is the identity status-- of any internal applications of 'apply' is preserved across the translate.---- Note: @transparently $ translate $ \\ e -> return e@ /is/ an identity rewrite.transparently::(Monoiddec,Monadm)=>Translatemdecexp1exp2->Translatemdecexp1exp2transparently(Translatem)=Translate$\e->transparentlyM(me)-- | 'runTranslate' executes the translation, returning either a failure message,-- or a success and the new parts of the environment.runTranslate::(Monoiddec,Monadm)=>Translatemdecexpres->dec->exp->m(EitherString(res,dec,Int))runTranslaterrdece=dores<-runRewriteM(applyrre)deccaseresofRewriteReturnMexp'Nothingc->return(Right(exp',mempty,theCountc))RewriteReturnMexp'(Justds)c->return(Right(exp',ds,theCountc))RewriteFailureMmsg->return(Leftmsg)