1{-# OPTIONS_GHC -Wall #-}
2module Transform.Substitute (subst) where
4import Control.Arrow (second, (***))
5import qualified Data.Set as Set
8import AST.Expression.General (Expr'(..))
9import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Pattern as Pattern
11import qualified AST.Variable as V
14subst :: String -> Canonical.Expr' -> Canonical.Expr' -> Canonical.Expr'
15subst old new expression =
16 let f (A a e) = A a (subst old new e) in
22 ExplicitList (map f exprs)
25 Binop op (f e1) (f e2)
28 | Set.member old (Pattern.boundVars pattern) -> expression
29 | otherwise -> Lambda pattern (f body)
35 MultiIf (map (f *** f) branches)
38 | anyShadow -> expression
39 | otherwise -> Let (map substDef defs) (f body)
41 substDef (Canonical.Definition p e t) =
42 Canonical.Definition p (f e) t
45 any (Set.member old . Pattern.boundVars)
46 [ pattern | Canonical.Definition pattern _ _ <- defs ]
48 Var (V.Canonical home x) ->
50 V.Module _ -> expression
51 V.BuiltIn -> expression
52 V.Local -> if x == old then new else expression
55 Case (f e) (map substCase cases)
57 substCase (pattern, expr) =
58 if Set.member old (Pattern.boundVars pattern)
60 else (pattern, f expr)
63 Data tag (map f values)
65 Access record field ->
66 Access (f record) field
68 Remove record field ->
69 Remove (f record) field
71 Insert record field value ->
72 Insert (f record) field (f value)
74 Modify record fields ->
75 Modify (f record) (map (second f) fields)
78 Record (map (second f) fields)
80 Literal _ -> expression
82 Markdown _ _ -> expression
84 GLShader _ _ _ -> expression
89 PortOut name st signal ->
90 PortOut name st (f signal)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list