never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Rules.Vertical.MSet.ExplicitWithFlags where
4
5 import Conjure.Rules.Import
6 import Conjure.Rules.Definition
7
8
9
10 rule_Comprehension :: Rule
11 rule_Comprehension = "mset-comprehension{ExplicitWithFlags}" `Rule` theRule where
12 theRule z (Comprehension body gensOrConds) = do
13 (gocBefore, (pat, s), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
14 Generator (GenInExpr pat@Single{} s) -> return (pat, s)
15 _ -> na "rule_Comprehension"
16 TypeMSet{} <- typeOf s
17 MSet_ExplicitWithFlags <- representationOf s
18 [flags, values] <- downX1 s
19 DomainMatrix index _ <- domainOf values
20 let upd val old = lambdaToFunction pat old val
21 theyDo <- doDuplicatesMatter z
22 return
23 [ RuleResult
24 { ruleResultDescr = "Vertical rule for mset-comprehension, ExplicitWithFlags representation"
25 , ruleResultType = ExpressionRefinement
26 , ruleResultHook = Nothing
27 , ruleResult = do
28 (jPat, j) <- quantifiedVar
29 let val = [essence| &values[&j] |]
30 let outBody = upd val body
31 return $ Comprehension (if theyDo then [essence| &outBody * &flags[&j] |]
32 else outBody)
33 $ gocBefore
34 ++ [ Generator (GenDomainNoRepr jPat index)
35 , Condition [essence| &flags[&j] > 0 |]
36 ]
37 ++ transformBi (upd val) gocAfter
38 } ]
39 theRule _ _ = na "rule_Comprehension"
40
41
42 rule_Freq :: Rule
43 rule_Freq = "mset-freq{ExplicitWithFlags}" `namedRule` theRule where
44 theRule p = do
45 (mset, x) <- match opFreq p
46 TypeMSet{} <- typeOf mset
47 MSet_ExplicitWithFlags <- representationOf mset
48 [flags, values] <- downX1 mset
49 DomainMatrix index _ <- domainOf values
50 return
51 ( "Vertical rule for mset-freq, ExplicitWithFlags representation"
52 , do
53 (iPat, i) <- quantifiedVar
54 return
55 [essence|
56 sum([ &flags[&i]
57 | &iPat : &index
58 , &values[&i] = &x
59 ])
60 |]
61 )