Skip to content

Commit 16e9acb

Browse files
author
Tom Harding
authored
Merge pull request #18 from ju1m/fix-14
Fix invalid input due to back-propagation, fixes #14
2 parents 0c123de + ba2605d commit 16e9acb

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

examples/Issue14.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{-# Language BlockArguments #-}
2+
{-# Language FlexibleContexts #-}
3+
{-# Language PartialTypeSignatures #-}
4+
{-# Language TypeApplications #-}
5+
{-# Options_GHC -Wno-partial-type-signatures #-}
6+
module Issue14 where
7+
8+
import Control.Monad.Watson (whenever, Watson)
9+
import Data.Holmes hiding (whenever)
10+
import Test.Hspec
11+
import Data.Word (Word8)
12+
import Data.Typeable (Typeable)
13+
14+
issue14 ::
15+
AbsR (jsl int) =>
16+
Enum (Raw (jsl int)) =>
17+
EqC jsl int =>
18+
EqR jsl =>
19+
Input (jsl int) =>
20+
Num (Raw (jsl int)) =>
21+
Num (jsl int) =>
22+
SumR (jsl int) =>
23+
Typeable int =>
24+
[ [jsl int] ]
25+
issue14 = do
26+
let guesses = 2 `from` [1 .. 3] :: Config (Watson _) _
27+
guesses `whenever` \[a, b] ->
28+
(a .+ b) .== 5
29+
30+
spec_issue14 :: Spec
31+
spec_issue14 = do
32+
it "handles constraints from the output when refining Defined inputs" do
33+
issue14 @Defined @Int `shouldBe` [ [2,3], [3,2] ]
34+
it "handles constraints from the output when refining Intersect inputs" do
35+
issue14 @Intersect @Word8 `shouldBe` [ [2,3], [3,2] ]

holmes.cabal

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

41-
build-depends: base >= 4.12 && < 4.15
41+
build-depends: base >= 4.12 && < 4.16
4242
, containers >= 0.6 && < 0.7
4343
, hashable >= 1.3 && < 1.4
4444
, hedgehog >= 1.0 && < 1.1
@@ -62,15 +62,16 @@ test-suite examples
6262
build-depends: base
6363
, hashable >= 1.3 && < 1.4
6464
, holmes
65-
, hspec >= 2.7 && < 2.8
65+
, hspec >= 2.7 && < 2.9
6666
, split >= 0.2 && < 0.3
6767
, unordered-containers >= 0.2 && < 0.3
68-
, relude >= 0.6 && < 0.8
68+
, relude >= 0.6 && < 1.1
6969
, tasty >= 1.2 && < 1.5
7070
, tasty-discover
7171
, tasty-hspec
7272

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

7677
ghc-options: -Wall -Wextra -threaded
@@ -125,7 +126,7 @@ test-suite readme
125126
build-depends: base
126127
, hashable >= 1.3 && < 1.4
127128
, holmes
128-
, hspec >= 2.7 && < 2.8
129+
, hspec >= 2.7 && < 2.9
129130
main-is: README.lhs
130131
type: exitcode-stdio-1.0
131132
default-language: Haskell2010

src/Data/JoinSemilattice/Defined.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ instance Fractional x => Fractional (Defined x) where
9393
fromRational = pure . fromRational
9494
recip = fmap recip
9595

96-
instance Input (Defined content) where
96+
instance Eq content => Input (Defined content) where
9797
type Raw (Defined content) = content
9898

9999
from count options = Config (replicate count Unknown) do
100100
pure . \case
101101
Unknown -> map Exactly options
102-
decided -> [ decided ]
102+
Exactly a | a `elem` options -> [Exactly a]
103+
| otherwise -> [Conflict]
104+
Conflict -> [Conflict]

0 commit comments

Comments
 (0)