Skip to content
GitLab
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
c6870b2f
Commit
c6870b2f
authored
Jan 03, 2015
by
Andrey Mokhov
Browse files
Implement joinArgs and joinArgsWithSpaces as variadic functions.
parent
60843423
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Base.hs
View file @
c6870b2f
...
...
@@ -23,6 +23,7 @@ data Stage = Stage0 | Stage1 | Stage2 | Stage3 deriving (Eq, Enum)
type
Args
=
Action
[
String
]
type
Condition
=
Action
Bool
instance
Monoid
a
=>
Monoid
(
Action
a
)
where
...
...
@@ -35,36 +36,42 @@ class ShowAction a where
instance
ShowAction
String
where
showAction
=
return
instance
ShowAction
(
Action
String
)
where
showAction
=
id
arg
::
ShowAction
a
=>
[
a
]
->
Args
arg
=
mapM
showAction
type
ArgsCombine
=
Args
->
Args
->
Args
class
Collect
a
where
collect
::
Args
->
a
collect
::
ArgsCombine
->
Args
->
a
instance
Collect
Args
where
collect
=
id
collect
=
const
id
instance
(
ShowAction
a
,
Collect
r
)
=>
Collect
(
a
->
r
)
where
collect
prev
next
=
collect
$
do
next'
<-
showAction
next
prev
<>
return
[
next'
]
collect
combine
x
=
\
y
->
collect
combine
$
x
`
combine
`
arg
[
y
]
instance
Collect
r
=>
Collect
(
Args
->
r
)
where
collect
combine
x
=
\
y
->
collect
combine
$
x
`
combine
`
y
args
::
Collect
a
=>
a
args
=
collect
mempty
args
=
collect
(
<>
)
mempty
intercalateArgs
::
String
->
Args
->
Args
intercalateArgs
s
args
=
do
as
<-
args
return
[
intercalate
s
as
]
joinArgs
::
Collect
a
=>
a
joinArgs
=
collect
(
\
x
y
->
intercalateArgs
""
x
<>
y
)
mempty
joinArgsWithSpaces
::
Args
->
Args
joinArgsWithSpaces
=
intercalateArgs
" "
joinArgsWithSpaces
::
Collect
a
=>
a
joinArgsWithSpaces
=
collect
(
\
x
y
->
intercalateArgs
" "
x
<>
y
)
mempty
joinArgs
::
Args
->
Args
joinArgs
=
intercalateArgs
""
intercalateArgs
::
String
->
Args
->
Args
intercalateArgs
s
as
=
do
as'
<-
as
return
[
intercalate
s
as'
]
splitArgs
::
Args
->
Args
splitArgs
=
fmap
(
concatMap
words
)
filterOut
::
Args
->
[
String
]
->
Args
filterOut
a
rg
s
list
=
filter
(`
notElem
`
list
)
<$>
a
rg
s
filterOut
as
list
=
filter
(`
notElem
`
list
)
<$>
as
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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