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
Packages
Cabal
Commits
81768070
Commit
81768070
authored
Oct 08, 2016
by
Mikhail Glushenkov
Committed by
GitHub
Oct 08, 2016
Browse files
Merge pull request #3948 from phadej/module-name-from-components
Add ModuleName.fromComponents
parents
8c88c52e
048855d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Cabal/Distribution/ModuleName.hs
View file @
81768070
...
...
@@ -15,10 +15,13 @@
module
Distribution.ModuleName
(
ModuleName
,
fromString
,
fromComponents
,
components
,
toFilePath
,
main
,
simple
,
-- * Internal
validModuleComponent
,
)
where
import
Prelude
()
...
...
@@ -74,18 +77,21 @@ simple str = ModuleName (stlFromStrings [str])
-- are parsing user input then use 'Distribution.Text.simpleParse' instead.
--
fromString
::
String
->
ModuleName
fromString
string
|
all
validModuleComponent
components'
=
ModuleName
(
stlFromStrings
components'
)
|
otherwise
=
error
badName
fromString
string
=
fromComponents
(
split
string
)
where
components'
=
split
string
badName
=
"ModuleName.fromString: invalid module name "
++
show
string
split
cs
=
case
break
(
==
'.'
)
cs
of
(
chunk
,
[]
)
->
chunk
:
[]
(
chunk
,
_
:
rest
)
->
chunk
:
split
rest
-- | Construct a 'ModuleName' from valid module components, i.e. parts
-- separated by dots.
fromComponents
::
[
String
]
->
ModuleName
fromComponents
components'
|
all
validModuleComponent
components'
=
ModuleName
(
stlFromStrings
components'
)
|
otherwise
=
error
badName
where
badName
=
"ModuleName.fromComponents: invalid components "
++
show
components'
-- | The module name @Main@.
--
main
::
ModuleName
...
...
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