1{-# LANGUAGE MultiParamTypeClasses #-} 2 3{- | 4 /DEPRECATED/: Use "Data.Generics.Uniplate.Direct" instead. 5 6 This module supplies a method for writing 'Biplate' instances more easily. 7 This module requires fewest extensions, highest performance, and most instance 8 definitions. 9 10 To take an example: 11 12 > data Expr = Var Int | Pos Expr String | Neg Expr | Add Expr Expr 13 > data Stmt = Seq [Stmt] | Sel [Expr] | Let String Expr 14 > 15 > instance Uniplate Expr where 16 > uniplate (Var x ) = plate Var |- x 17 > uniplate (Pos x y) = plate Pos |* x |- y 18 > uniplate (Neg x ) = plate Neg |* x 19 > uniplate (Add x y) = plate Add |* x |* y 20 > 21 > instance Biplate Expr Expr where 22 > biplate = plateSelf 23 > 24 > instance Uniplate Stmt where 25 > uniplate (Seq x ) = plate Seq ||* x 26 > uniplate (Sel x ) = plate Sel ||+ x 27 > uniplate (Let x y) = plate Let |- x |- y 28 > 29 > instance Biplate Stmt Stmt where 30 > biplate = plateSelf 31 > 32 > instance Biplate Stmt Expr where 33 > biplate (Seq x ) = plate Seq ||+ x 34 > biplate (Sel x ) = plate Sel ||* x 35 > biplate (Let x y) = plate Let |- x |* y 36-} 37 38 39module Data.Generics.PlateDirect 40 {-# DEPRECATED "Use Data.Generics.Uniplate.Direct instead" #-} 41 ( 42 module Data.Generics.Biplate, 43 -- * The Combinators 44 plate, plateSelf, 45 (|+), (|-), (|*), (||+), (||*) 46 ) where 47 48import Data.Generics.Biplate 49 50 51type Type from to = (Str to, Str to -> from) 52 53-- | The main combinator used to start the chain. 54-- 55-- The following rule can be used for optimisation: 56-- 57-- > plate Ctor |- x == plate (Ctor x) 58plate :: from -> Type from to 59plate f = (Zero, \_ -> f) 60 61 62-- | The field to the right is the target. 63(|*) :: Type (to -> from) to -> to -> Type from to 64(|*) (xs,x_) y = (Two xs (One y),\(Two xs (One y)) -> x_ xs y) 65 66 67 68-- | The field to the right may contain the target. 69(|+) :: Biplate item to => Type (item -> from) to -> item -> Type from to 70(|+) (xs,x_) y = case biplate y of 71 (ys,y_) -> (Two xs ys, \(Two xs ys) -> x_ xs (y_ ys)) 72 73 74-- | The field to the right /does not/ contain the target. 75(|-) :: Type (item -> from) to -> item -> Type from to 76(|-) (xs,x_) y = (xs,\xs -> x_ xs y) 77 78 79-- | The field to the right is a list of the type of the target 80(||*) :: Type ([to] -> from) to -> [to] -> Type from to 81(||*) (xs,x_) y = (Two xs (listStr y), \(Two xs ys) -> x_ xs (strList ys)) 82 83 84-- | The field to the right is a list of types which may contain the target 85(||+) :: Biplate item to => Type ([item] -> from) to -> [item] -> Type from to 86(||+) (xs,x_) y = case plateListDiff y of 87 (ys,y_) -> (Two xs ys, \(Two xs ys) -> x_ xs (y_ ys)) 88 where 89 plateListDiff [] = plate [] 90 plateListDiff (x:xs) = plate (:) |+ x ||+ xs 91 92 93-- | Used for 'PlayAll' definitions where both types are the same. 94plateSelf :: to -> Type to to 95plateSelf x = (One x, \(One x) -> x) 96