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
Packages
Cabal
Commits
f2bf8347
Commit
f2bf8347
authored
Jul 10, 2013
by
Benno Fünfstück
Browse files
Add Functor/Applicative instances for ParseResult
ParseResult is a Monad, so it should also be a Functor and an Applicative.
parent
cd935e2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Cabal/Distribution/ParseUtils.hs
View file @
f2bf8347
...
...
@@ -87,7 +87,8 @@ import Data.Char (isSpace, toLower, isAlphaNum, isDigit)
import
Data.Maybe
(
fromMaybe
)
import
Data.Tree
as
Tree
(
Tree
(
..
),
flatten
)
import
qualified
Data.Map
as
Map
import
Control.Monad
(
foldM
)
import
Control.Monad
(
foldM
)
import
Control.Applicative
(
Applicative
(
..
))
import
System.FilePath
(
normalise
)
import
Data.List
(
sortBy
)
...
...
@@ -115,6 +116,14 @@ showPWarning fpath (UTFWarning line fname) =
data
ParseResult
a
=
ParseFailed
PError
|
ParseOk
[
PWarning
]
a
deriving
Show
instance
Functor
ParseResult
where
fmap
f
(
ParseFailed
err
)
=
ParseFailed
err
fmap
f
(
ParseOk
ws
x
)
=
ParseOk
ws
$
f
x
instance
Applicative
ParseResult
where
pure
=
ParseOk
[]
f
<*>
a
=
join
$
fmap
(
\
f'
->
fmap
f'
a
)
instance
Monad
ParseResult
where
return
=
ParseOk
[]
ParseFailed
err
>>=
_
=
ParseFailed
err
...
...
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