Skip to content

Commit 4ed1b11

Browse files
author
Julien Moutinho
committed
fix resolve
1 parent 16e9acb commit 4ed1b11

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

holmes.cabal

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ library
3838
, Data.JoinSemilattice.Class.Zipping
3939
, Data.CDCL
4040

41-
build-depends: base >= 4.12 && < 4.16
42-
, containers >= 0.6 && < 0.7
43-
, hashable >= 1.3 && < 1.4
44-
, hedgehog >= 1.0 && < 1.1
45-
, logict >= 0.7 && < 0.8
46-
, mtl >= 2.2 && < 2.3
47-
, primitive >= 0.7 && < 0.8
48-
, transformers >= 0.5 && < 0.6
49-
, unordered-containers >= 0.2 && < 0.3
41+
build-depends: base >= 4.12
42+
, containers >= 0.6
43+
, hashable >= 1.3
44+
, hedgehog >= 1.0
45+
, logict >= 0.7
46+
, mtl >= 2.2
47+
, primitive >= 0.7
48+
, transformers >= 0.5
49+
, unordered-containers >= 0.2
5050

5151
ghc-options: -Wall -Wextra
5252
hs-source-dirs: src
@@ -60,23 +60,24 @@ test-suite examples
6060
main-is: Main.hs
6161

6262
build-depends: base
63-
, hashable >= 1.3 && < 1.4
63+
, hashable >= 1.3
6464
, holmes
65-
, hspec >= 2.7 && < 2.9
66-
, split >= 0.2 && < 0.3
67-
, unordered-containers >= 0.2 && < 0.3
68-
, relude >= 0.6 && < 1.1
69-
, tasty >= 1.2 && < 1.5
65+
, hspec >= 2.7
66+
, split >= 0.2
67+
, unordered-containers >= 0.2
68+
, relude >= 0.6
69+
, tasty >= 1.2
7070
, tasty-discover
7171
, tasty-hspec
7272

73-
other-modules: Futoshiki
73+
other-modules:
74+
Futoshiki
7475
, Issue14
7576
, WaveFunctionCollapse
7677

7778
ghc-options: -Wall -Wextra -threaded
7879
hs-source-dirs: examples
79-
build-tool-depends: tasty-discover:tasty-discover
80+
-- build-tool-depends: tasty-discover:tasty-discover
8081
default-language: Haskell2010
8182

8283
--------------------------------------------------
@@ -87,13 +88,13 @@ test-suite test
8788
main-is: Main.hs
8889

8990
build-depends: base
90-
, containers >= 0.6 && < 0.7
91-
, hashable >= 1.3 && < 1.4
92-
, hedgehog >= 1.0 && < 1.1
91+
, containers >= 0.6
92+
, hashable >= 1.3
93+
, hedgehog >= 1.0
9394
, holmes
94-
, primitive >= 0.7 && < 0.8
95-
, transformers >= 0.5 && < 0.6
96-
, tasty >= 1.2 && < 1.5
95+
, primitive >= 0.7
96+
, transformers >= 0.5
97+
, tasty >= 1.2
9798
, tasty-discover
9899
, tasty-hedgehog
99100
, tasty-hspec
@@ -115,20 +116,20 @@ test-suite test
115116

116117
ghc-options: -Wall -Wextra -threaded
117118
hs-source-dirs: test
118-
build-tool-depends: markdown-unlit:markdown-unlit
119-
, tasty-discover:tasty-discover
119+
-- build-tool-depends: markdown-unlit:markdown-unlit
120+
-- , tasty-discover:tasty-discover
120121
default-language: Haskell2010
121122

122123
--------------------------------------------------
123124
-- LITERATE HASKELL README / HSPEC RUNNER
124125

125-
test-suite readme
126-
build-depends: base
127-
, hashable >= 1.3 && < 1.4
128-
, holmes
129-
, hspec >= 2.7 && < 2.9
130-
main-is: README.lhs
131-
type: exitcode-stdio-1.0
132-
default-language: Haskell2010
133-
ghc-options: -pgmL markdown-unlit -Wall
134-
build-tool-depends: markdown-unlit:markdown-unlit
126+
--test-suite readme
127+
-- build-depends: base
128+
-- , hashable >= 1.3
129+
-- , holmes
130+
-- , hspec >= 2.7
131+
-- main-is: README.lhs
132+
-- type: exitcode-stdio-1.0
133+
-- default-language: Haskell2010
134+
-- ghc-options: -pgmL markdown-unlit -Wall
135+
-- build-tool-depends: markdown-unlit:markdown-unlit

src/Data/CDCL.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ implies (Group group) candidate = any (`subsumes` candidate) group
116116
-- __subset__ of the switches in @y@. In other words, the @x@ 'Rule' will match
117117
-- /everything/ that @y@ will.
118118
subsumes :: Rule -> Rule -> Bool
119-
subsumes (Rule these) (Rule those) = HashMap.foldrWithKey check True these
120-
where check key value acc = HashMap.lookup key those == Just value && acc
119+
subsumes (Rule x) (Rule y) = HashMap.foldrWithKey check True x
120+
where check key v acc = HashMap.lookup key y == Just v && acc
121121

122122
-- | Add a new 'Rule' to a 'Group'. Attempt to calculate any 'refinements' of
123123
-- the rule, and generalise the 'Group' as far as possible.
@@ -126,11 +126,17 @@ resolve rule group | group `implies` rule = group
126126
resolve rule@(Rule config) group@(Group rules)
127127
= case refinements rule group of
128128
[] -> Group case HashMap.toList config of
129-
[ (key, value) ] -> do -- Unit propagation
129+
[ (key, x) ] -> do -- Unit propagation
130130
HashSet.insert rule $ rules & HashSet.map \(Rule current) -> do
131-
if HashMap.lookup key current /= Just value
132-
then Rule (HashMap.delete key current)
133-
else rule
131+
Rule $ case HashMap.lookup key current of
132+
-- The unit does not appear in the current rule : keep the current rule.
133+
Nothing -> current
134+
-- The unit subsumes the current rule : delete the current rule.
135+
Just y | y == x -> config
136+
-- If the unit matches, the current rule is useless for that group to match.
137+
-- Otherwise the unit does not match, but then the current rule
138+
-- does not need to recheck that : delete the unit from the current rule.
139+
| otherwise {- y == not x -} -> HashMap.delete key current
134140

135141
_ -> rules & HashSet.filter (not . (rule `subsumes`))
136142
& HashSet.insert rule

0 commit comments

Comments
 (0)