1{-# OPTIONS_GHC -Wall #-}
2module Optimize.Substitute (subst) where
4import Control.Arrow (second, (***))
6import AST.Expression.General (Expr'(..), PortImpl(..))
7import qualified AST.Expression.Optimized as Optimized
8import qualified AST.Pattern as Pattern
9import qualified AST.Variable as V
10import Elm.Utils ((|>))
11import qualified Reporting.Annotation as A
14subst :: String -> Optimized.Expr' -> Optimized.Expr' -> Optimized.Expr'
15subst old new expression =
16 let f (A.A a e) = A.A a (subst old new e) in
22 ExplicitList (map f exprs)
24 Binop op left right ->
25 Binop op (f left) (f right)
27 Lambda pattern body ->
28 if Pattern.member old pattern
30 else Lambda pattern (f body)
35 If branches finally ->
36 If (map (f *** f) branches) (f finally)
41 else Let (map substDef defs) (f body)
43 substDef (Optimized.Definition facts pattern expr) =
44 Optimized.Definition facts pattern (f expr)
47 map (\(Optimized.Definition _ p _) -> p) defs
48 |> any (Pattern.member old)
50 Var (V.Canonical home x) ->
59 if x == old then new else expression
62 if x == old then new else expression
65 Case (f e) (map substCase cases)
67 substCase (pattern, expr) =
68 if Pattern.member old pattern
70 else (pattern, f expr)
73 Data tag (map f values)
75 Access record field ->
76 Access (f record) field
78 Update record fields ->
79 Update (f record) (map (second f) fields)
82 Record (map (second f) fields)
97 Out name (f expr) tipe
99 Task name expr tipe ->
100 Task name (f expr) tipe
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