Examples of monadic effects inside rewriting function in Hoopl?

The type (redirection) of rewriting functions in Hoopl is specified by mkFRewrite :

 mkFRewrite :: (FuelMonad m) => (forall e x. nex -> f -> m (Maybe (hoopl-3.8.6.1:Compiler.Hoopl.Dataflow.Graph nex))) -> FwdRewrite mnf 

Type m implies that I can use monadic effects when overwriting. The article “Hoopl: a modular, reusable library for analyzing and transforming data flow” says the same thing in section 4.3 “Overwrite function and client monad”.

Can someone give me an example of a rewriting function that has monadic non-Hoopl effects built in ? For example, a rewriter that uses the state monad or performs some I / O.

+4
source share
1 answer

It should be pretty simple, just chase the types.

You need the FwdRewrite mnf with a custom m value, so you can pass it to the following function:

 analyzeAndRewriteFwd :: forall mnfex entries. (CheckpointMonad m, NonLocal n, LabelsPtr entries) => FwdPass mnf -> MaybeC e entries -> Graph nex -> Fact ef -> m (Graph nex, FactBase f, MaybeO xf) 

So the only restriction on m you have is that it is CheckpointMonad ; then when you start the passage, you will get the final monadic value, which you can run yourself.

In fact, GHC Hoopl conveys the use of m as SimplUniqMonad , so we can get fresh labels while we work on the chart.

 {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE TypeFamilies #-} import Compiler.Hoopl import Control.Monad.State type StateFuel sa = CheckingFuelMonad (State s) a instance CheckpointMonad (State s) where type Checkpoint (State s) = s checkpoint = get restart = put 
+2
source

All Articles