Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
9140548b
Commit
9140548b
authored
Dec 30, 2015
by
Andrey Mokhov
Browse files
Add Expressions.removePair function to remove pairs of arguments.
parent
9e2ddcb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Expression.hs
View file @
9140548b
...
@@ -3,7 +3,8 @@ module Expression (
...
@@ -3,7 +3,8 @@ module Expression (
-- * Expressions
-- * Expressions
Expr
,
DiffExpr
,
fromDiffExpr
,
Expr
,
DiffExpr
,
fromDiffExpr
,
-- ** Operators
-- ** Operators
apply
,
append
,
arg
,
remove
,
appendSub
,
appendSubD
,
filterSub
,
removeSub
,
apply
,
append
,
arg
,
remove
,
removePair
,
appendSub
,
appendSubD
,
filterSub
,
removeSub
,
-- ** Evaluation
-- ** Evaluation
interpret
,
interpretPartial
,
interpretWithStage
,
interpretDiff
,
interpret
,
interpretPartial
,
interpretWithStage
,
interpretDiff
,
-- ** Predicates
-- ** Predicates
...
@@ -76,6 +77,16 @@ append x = apply (<> x)
...
@@ -76,6 +77,16 @@ append x = apply (<> x)
remove
::
Eq
a
=>
[
a
]
->
DiffExpr
[
a
]
remove
::
Eq
a
=>
[
a
]
->
DiffExpr
[
a
]
remove
xs
=
apply
$
filter
(`
notElem
`
xs
)
remove
xs
=
apply
$
filter
(`
notElem
`
xs
)
-- | Remove given pair of elements from a list expression
-- Example: removePair "-flag" "b" ["-flag", "a", "-flag", "b"] = ["-flag", "a"]
removePair
::
Eq
a
=>
a
->
a
->
DiffExpr
[
a
]
removePair
x
y
=
apply
filterPair
where
filterPair
(
z1
:
z2
:
zs
)
=
if
x
==
z1
&&
y
==
z2
then
filterPair
zs
else
z1
:
filterPair
(
z2
:
zs
)
filterPair
zs
=
zs
-- | Apply a predicate to an expression
-- | Apply a predicate to an expression
applyPredicate
::
Monoid
a
=>
Predicate
->
Expr
a
->
Expr
a
applyPredicate
::
Monoid
a
=>
Predicate
->
Expr
a
->
Expr
a
applyPredicate
predicate
expr
=
do
applyPredicate
predicate
expr
=
do
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment