Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex D
GHC
Commits
2a394246
Commit
2a394246
authored
Aug 11, 2019
by
Richard Lupton
Committed by
Marge Bot
Aug 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Foldable instance of Bag for specialised Bag folds (#16969)
parent
3a1efe1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
19 deletions
+26
-19
compiler/utils/Bag.hs
compiler/utils/Bag.hs
+26
-19
No files found.
compiler/utils/Bag.hs
View file @
2a394246
...
...
@@ -194,32 +194,26 @@ foldBag t u e (ListBag xs) = foldr (t.u) e xs
foldrBag
::
(
a
->
r
->
r
)
->
r
->
Bag
a
->
r
foldrBag
_
z
EmptyBag
=
z
foldrBag
k
z
(
UnitBag
x
)
=
k
x
z
foldrBag
k
z
(
TwoBags
b1
b2
)
=
foldrBag
k
(
foldrBag
k
z
b2
)
b1
foldrBag
k
z
(
ListBag
xs
)
=
foldr
k
z
xs
-- Maintained for backward compatibility - now just a specialisation of
-- Foldable.
foldrBag
=
Foldable
.
foldr
foldlBag
::
(
r
->
a
->
r
)
->
r
->
Bag
a
->
r
foldlBag
_
z
EmptyBag
=
z
foldlBag
k
z
(
UnitBag
x
)
=
k
z
x
foldlBag
k
z
(
TwoBags
b1
b2
)
=
foldlBag
k
(
foldlBag
k
z
b1
)
b2
foldlBag
k
z
(
ListBag
xs
)
=
foldl
k
z
xs
-- Maintained for backward compatibility - now just a specialisation of
-- Foldable.
foldlBag
=
Foldable
.
foldl
foldrBagM
::
(
Monad
m
)
=>
(
a
->
b
->
m
b
)
->
b
->
Bag
a
->
m
b
foldrBagM
_
z
EmptyBag
=
return
z
foldrBagM
k
z
(
UnitBag
x
)
=
k
x
z
foldrBagM
k
z
(
TwoBags
b1
b2
)
=
do
{
z'
<-
foldrBagM
k
z
b2
;
foldrBagM
k
z'
b1
}
foldrBagM
k
z
(
ListBag
xs
)
=
foldrM
k
z
xs
-- Maintained for backward compatibility - now just a specialisation of
-- Foldable.
foldrBagM
=
Foldable
.
foldrM
foldlBagM
::
(
Monad
m
)
=>
(
b
->
a
->
m
b
)
->
b
->
Bag
a
->
m
b
foldlBagM
_
z
EmptyBag
=
return
z
foldlBagM
k
z
(
UnitBag
x
)
=
k
z
x
foldlBagM
k
z
(
TwoBags
b1
b2
)
=
do
{
z'
<-
foldlBagM
k
z
b1
;
foldlBagM
k
z'
b2
}
foldlBagM
k
z
(
ListBag
xs
)
=
foldlM
k
z
xs
-- Maintained for backward compatibility - now just a specialisation of
-- Foldable.
foldlBagM
=
Foldable
.
foldlM
mapBag
::
(
a
->
b
)
->
Bag
a
->
Bag
b
mapBag
=
fmap
...
...
@@ -343,4 +337,17 @@ instance Data a => Data (Bag a) where
dataCast1
x
=
gcast1
x
instance
Foldable
.
Foldable
Bag
where
foldr
=
foldrBag
foldr
_
z
EmptyBag
=
z
foldr
k
z
(
UnitBag
x
)
=
k
x
z
foldr
k
z
(
TwoBags
b1
b2
)
=
foldr
k
(
foldr
k
z
b2
)
b1
foldr
k
z
(
ListBag
xs
)
=
foldr
k
z
xs
foldl
_
z
EmptyBag
=
z
foldl
k
z
(
UnitBag
x
)
=
k
z
x
foldl
k
z
(
TwoBags
b1
b2
)
=
foldl
k
(
foldl
k
z
b1
)
b2
foldl
k
z
(
ListBag
xs
)
=
foldl
k
z
xs
foldl'
_
z
EmptyBag
=
z
foldl'
k
z
(
UnitBag
x
)
=
k
z
x
foldl'
k
z
(
TwoBags
b1
b2
)
=
let
r1
=
foldl'
k
z
b1
in
seq
r1
$
foldl'
k
r1
b2
foldl'
k
z
(
ListBag
xs
)
=
foldl'
k
z
xs
Write
Preview
Markdown
is supported
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