packages feed

rewriting 0.2 → 0.2.1

raw patch · 5 files changed

+50/−17 lines, 5 filesdep ~regular

Dependency ranges changed: regular

Files

examples/expr/Expr.hs view
@@ -1,5 +1,4 @@-{-# LANGUAGE TypeFamilies  #-}-{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -fglasgow-exts #-}  import Generics.Regular.Rewriting @@ -11,18 +10,33 @@ infixl 7 :**: infixl 6 :++: -data Expr = Const Int | Expr :++: Expr | Expr :**: Expr deriving Show+data Expr = Const Int | Expr :++: Expr | Expr :**: Expr | Fun String [Expr] +  deriving Show -type instance PF Expr = K Int :+: I :*: I :+: I :*: I+type instance PF Expr = K Int :+: I :*: I :+: I :*: I :+: K String :*: [] :.: I instance Regular Expr where   from (Const n)    = L (K n)-  from (e1 :++: e2) = R (L  $ (I e1) :*: (I e2))-  from (e1 :**: e2) = R (R  $ (I e1) :*: (I e2))+  from (e1 :++: e2) = R (L $ (I e1) :*: (I e2))+  from (e1 :**: e2) = R (R (L $ (I e1) :*: (I e2)))+  from (Fun s le) = R (R (R (K s :*: Comp (fmap I le))))    to (L (K n))                     = Const n   to (R (L ((I r1) :*: (I r2)))) = r1 :++: r2-  to (R (R ((I r1) :*: (I r2)))) = r1 :**: r2+  to (R (R (L ((I r1) :*: (I r2))))) = r1 :**: r2+  to (R (R (R (K s :*: Comp l)))) = Fun s (fmap unI l)+  +data Nil+instance Constructor Nil where conName _ = "[]"+data Cons+instance Constructor Cons where conName _ = "(:)" +type instance PF1 [] = C Nil U :+: C Cons (I :*: [])  +instance Regular1 [] where+  from1 []    = L (C U)+  from1 (h:t) = R (C (I h :*: t))+  to1 (L (C U))           = []+  to1 (R (C (I h :*: t))) = h : t+ {-  -- with Con type constructors to specify constructor names. instance Regular Expr where@@ -38,6 +52,13 @@ -}  instance Rewrite Expr+instance Crush [] where crush = dft_crush+instance GMap [] where fmapM = dft_fmapM+instance GShow [] where gshowf = dft_gshowf+instance Zip [] where fzipM = dft_fzipM+instance LR [] where+  leftf = dft_leftf+  rightf = dft_rightf  ----------------------------------------------------------------------------- -- Example rules@@ -73,7 +94,12 @@   rule $ Const 1 :++: Const 1 :~>          Const 2 +rule7 :: Rule Expr+rule7 = +  rule $ \x -> Fun "square" [x] :~>+                x :**: x + ----------------------------------------------------------------------------- -- Tests -----------------------------------------------------------------------------@@ -115,6 +141,9 @@ test11 :: Maybe Expr test11 = rewriteM rule6 (Const 1 :++: Const 1) +test12 :: Maybe Expr+test12 = rewriteM rule7 (Fun "square" [Const 3])+ allTests :: [Maybe Expr] allTests = [ test1            , test2@@ -127,6 +156,7 @@            , test9            , test10            , test11+           , test12            ]  
rewriting.cabal view
@@ -1,5 +1,5 @@ name:                   rewriting-version:                0.2+version:                0.2.1 synopsis:               Generic rewriting library for regular datatypes. description: @@ -59,7 +59,8 @@                         Generics.Regular.Rewriting.Rules                         Generics.Regular.Rewriting.Strategies -  build-depends:        base >= 4.0 && < 5, containers >= 0.1, regular >= 0.1+  build-depends:        base >= 4.0 && < 5, containers >= 0.1,+                        regular >= 0.2 && < 0.3  -- Disabled the test flag for the moment since not all -- modules from the tests directory are properly included
src/Generics/Regular/Rewriting/Machinery.hs view
@@ -34,6 +34,7 @@  import Generics.Regular.Base import Generics.Regular.Functions+import qualified Generics.Regular.Functions.Show as G import Generics.Regular.Rewriting.Rules  @@ -45,7 +46,7 @@ -- -- To be able to use the rewriting functions, the user is required to provide -- an instance of this type class.-class (Regular a, CrushR (PF a), GMap (PF a), GShow (PF a)+class (Regular a, Crush (PF a), GMap (PF a), G.Show (PF a)       , Zip (PF a), LR (PF a), Functor (PF a)) => Rewrite a  
src/Generics/Regular/Rewriting/Rules.hs view
@@ -1,6 +1,7 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE TypeFamilies     #-}-{-# LANGUAGE TypeOperators    #-}+{-# LANGUAGE FlexibleContexts     #-}+{-# LANGUAGE TypeFamilies         #-}+{-# LANGUAGE TypeOperators        #-}+{-# LANGUAGE UndecidableInstances #-}  ----------------------------------------------------------------------------- -- |@@ -129,7 +130,7 @@   base x                   = x   diag x                   = [x] -instance (Builder a, Regular b, LR (PF b)) => Builder (b -> a) where+instance (b ~ Target a, Builder a, Regular b, LR (PF b)) => Builder (b -> a) where   type Target (b -> a) = Target a   base f               = base (f left)   @@ -146,14 +147,14 @@  -- | Transforms a rule specification to a rule and throws a runtime error if -- an unbound metavariable occurs in the right-hand side of the rule.-rule :: ( Builder r, CrushR (PF (Target r))+rule :: ( Builder r, Crush (PF (Target r))         , Functor (PF (Target r)), Zip (PF (Target r)))      => r -> Rule (Target r) rule = maybe (error "rule: unbound metavariable") id . ruleM  -- | Transforms a rule specification to a rule and returns @Nothing@ if -- an unbound metavariable occurs in the right-hand side of the rule.-ruleM :: (  Builder r, CrushR (PF (Target r))+ruleM :: (  Builder r, Crush (PF (Target r))           , Zip (PF (Target r)), Functor (PF (Target r)))       => r -> Maybe (Rule (Target r)) ruleM f = checkMetavars $ foldr1 mergeRules rules
src/Generics/Regular/Rewriting/Strategies.hs view
@@ -35,7 +35,7 @@  import Control.Monad -import Generics.Regular.Base+import Generics.Regular.Base (Regular(..), PF) import Generics.Regular.Functions