Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
Cabal
Commits
c80b870f
Commit
c80b870f
authored
8 years ago
by
Oleg Grenrus
Browse files
Options
Downloads
Patches
Plain Diff
Lens experiment
parent
1b24aa36
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Cabal/tests/ParserTests.hs
+80
-2
80 additions, 2 deletions
Cabal/tests/ParserTests.hs
with
80 additions
and
2 deletions
Cabal/tests/ParserTests.hs
+
80
−
2
View file @
c80b870f
{-# LANGUAGE Rank2Types #-}
module
Main
where
module
Main
where
import
Control.Applicative
import
Control.Applicative
...
@@ -30,6 +31,12 @@ import qualified Distribution.Parsec.Types.Common as Parsec
...
@@ -30,6 +31,12 @@ import qualified Distribution.Parsec.Types.Common as Parsec
import
qualified
Distribution.Parsec.Types.ParseResult
as
Parsec
import
qualified
Distribution.Parsec.Types.ParseResult
as
Parsec
import
qualified
Distribution.ParseUtils
as
ReadP
import
qualified
Distribution.ParseUtils
as
ReadP
#
if
__GLASGOW_HASKELL__
>=
708
import
Data.Coerce
#
else
import
Unsafe.Coerce
#
endif
#
ifdef
HAS_STRUCT_DIFF
#
ifdef
HAS_STRUCT_DIFF
import
DiffInstances
()
import
DiffInstances
()
import
StructDiff
import
StructDiff
...
@@ -98,8 +105,14 @@ compareTest pfx fpath bsl
...
@@ -98,8 +105,14 @@ compareTest pfx fpath bsl
parsec
<-
maybe
(
print
readp
>>
exitFailure
)
return
parsec'
parsec
<-
maybe
(
print
readp
>>
exitFailure
)
return
parsec'
-- Old parser is broken for many descriptions, and other free text fields
-- Old parser is broken for many descriptions, and other free text fields
let
readp0
=
readp
{
packageDescription
=
(
packageDescription
readp
)
{
description
=
""
,
synopsis
=
""
,
maintainer
=
""
}}
let
readp0
=
readp
let
parsec0
=
parsec
{
packageDescription
=
(
packageDescription
parsec
)
{
description
=
""
,
synopsis
=
""
,
maintainer
=
""
}}
&
set
(
lensPackageDescription
.
lensDescription
)
""
&
set
(
lensPackageDescription
.
lensSynopsis
)
""
&
set
(
lensPackageDescription
.
lensMaintainer
)
""
let
parsec0
=
parsec
&
set
(
lensPackageDescription
.
lensDescription
)
""
&
set
(
lensPackageDescription
.
lensSynopsis
)
""
&
set
(
lensPackageDescription
.
lensMaintainer
)
""
if
readp0
==
parsec0
if
readp0
==
parsec0
then
return
()
then
return
()
...
@@ -237,3 +250,68 @@ fieldLinesToString fieldLines =
...
@@ -237,3 +250,68 @@ fieldLinesToString fieldLines =
B8
.
unpack
$
B
.
concat
$
bsFromFieldLine
<$>
fieldLines
B8
.
unpack
$
B
.
concat
$
bsFromFieldLine
<$>
fieldLines
where
where
bsFromFieldLine
(
Parsec
.
FieldLine
_
bs
)
=
bs
bsFromFieldLine
(
Parsec
.
FieldLine
_
bs
)
=
bs
-------------------------------------------------------------------------------
-- Distribution.Compat.Lens
-------------------------------------------------------------------------------
type
Lens'
s
a
=
forall
f
.
Functor
f
=>
(
a
->
f
a
)
->
s
->
f
s
type
Traversal'
s
a
=
forall
f
.
Applicative
f
=>
(
a
->
f
a
)
->
s
->
f
s
type
ASetter'
s
a
=
(
a
->
I
a
)
->
s
->
I
s
-- | Replace the target of a 'Lens'' or 'Traversal'' with a constant value.
set
::
ASetter'
s
a
->
a
->
s
->
s
set
l
x
=
over
l
(
const
x
)
-- | Modify the target of a 'Lens'' or all the targets of a 'Traversal''
-- with a function.
over
::
ASetter'
s
a
->
(
a
->
a
)
->
s
->
s
#
if
__GLASGOW_HASKELL__
>=
708
over
l
f
=
coerce
.
l
(
coerce
.
f
)
#
else
over
l
f
=
unsafeCoerce
.
l
(
unsafeCoerce
.
f
)
#
endif
-- | '&' is a reverse application operator
(
&
)
::
a
->
(
a
->
b
)
->
b
(
&
)
=
flip
(
$
)
{-# INLINE (&) #-}
infixl
1
&
-- | Infix flipped 'fmap'.
--
-- @
-- ('<&>') = 'flip' 'fmap'
-- @
(
<&>
)
::
Functor
f
=>
f
a
->
(
a
->
b
)
->
f
b
as
<&>
f
=
f
<$>
as
{-# INLINE (<&>) #-}
infixl
1
<&>
-------------------------------------------------------------------------------
-- Distribution.Compat.BasicFunctors
-------------------------------------------------------------------------------
newtype
I
a
=
I
a
unI
::
I
a
->
a
unI
(
I
x
)
=
x
instance
Functor
I
where
fmap
f
(
I
x
)
=
I
(
f
x
)
-------------------------------------------------------------------------------
-- Distribution.PackageDescription.Lens
-------------------------------------------------------------------------------
lensPackageDescription
::
Lens'
GenericPackageDescription
PackageDescription
lensPackageDescription
f
s
=
f
(
packageDescription
s
)
<&>
\
a
->
s
{
packageDescription
=
a
}
lensDescription
,
lensSynopsis
,
lensMaintainer
::
Lens'
PackageDescription
String
lensDescription
f
s
=
f
(
description
s
)
<&>
\
a
->
s
{
description
=
a
}
lensSynopsis
f
s
=
f
(
synopsis
s
)
<&>
\
a
->
s
{
synopsis
=
a
}
lensMaintainer
f
s
=
f
(
maintainer
s
)
<&>
\
a
->
s
{
maintainer
=
a
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment