never executed always true always false
1 module Conjure.Rules.Import
2 ( module X
3 , doDuplicatesMatter
4 , referenceToComprehensionVar
5 ) where
6
7 import Conjure.Prelude as X
8 import Conjure.Bug as X
9
10 import Conjure.Language as X
11
12 import Conjure.Language.CategoryOf as X ( categoryOf, Category(..) )
13 import Conjure.Language.RepresentationOf as X ( representationOf, hasRepresentation, sameRepresentation )
14
15 import Conjure.Compute.DomainOf as X ( domainOf, indexDomainsOf )
16 import Conjure.Compute.DomainUnion as X ( domainUnion, domainUnions )
17 import Conjure.Language.DomainSizeOf as X ( domainSizeOf )
18 import Conjure.Language.Instantiate as X ( entailed )
19
20 import Conjure.Rules.Definition as X ( Rule(..), namedRule, matchFirst )
21 import Conjure.Representations as X ( downX1 )
22
23 -- uniplate
24 import Data.Generics.Uniplate.Zipper as Zipper ( Zipper, up, hole )
25
26
27
28 -- keep going up, until finding a quantifier
29 -- when found, return whether this quantifier requires us to remove duplicates or not
30 -- if none exists, do not apply the rule.
31 -- (or maybe we should call bug right ahead, it can't be anything else.)
32 doDuplicatesMatter :: MonadFailDoc m => Zipper.Zipper a Expression -> m Bool
33 doDuplicatesMatter z0 =
34 case Zipper.up z0 of
35 Nothing -> na "doDuplicatesMatter 1"
36 Just z -> do
37 let h = Zipper.hole z
38 case ( match opAnd h, match opOr h, match opSum h
39 , match opProduct h, match opMin h, match opMax h ) of
40 (Just{}, _, _, _, _, _) -> return False -- and
41 (_, Just{}, _, _, _, _) -> return False -- or
42 (_, _, Just{}, _, _, _) -> return True -- sum
43 (_, _, _, Just{}, _, _) -> return True -- product
44 (_, _, _, _, Just{}, _) -> return False -- min
45 (_, _, _, _, _, Just{}) -> return False -- max
46 _ -> na "doDuplicatesMatter 2"
47 -- case Zipper.up z of
48 -- Nothing -> na "doDuplicatesMatter"
49 -- Just u -> doDuplicatesMatter u
50
51 referenceToComprehensionVar :: Expression -> Bool
52 referenceToComprehensionVar (Reference _ (Just InComprehension{})) = True
53 referenceToComprehensionVar (Op (MkOpIndexing (OpIndexing m _))) = referenceToComprehensionVar m
54 referenceToComprehensionVar _ = False
55