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
7
8 rule_Comprehension :: Rule
9 rule_Comprehension = "mset-comprehension{ExplicitWithFlags}" `namedRuleZ` theRule where
10 theRule z (Comprehension body gensOrConds) = do
11 (gocBefore, (pat, s), gocAfter) <- matchFirst gensOrConds $ \case
12 Generator (GenInExpr pat@Single{} s) -> return (pat, s)
13 _ -> na "rule_Comprehension"
14 TypeMSet{} <- typeOf s
15 MSet_ExplicitWithFlags <- representationOf s
16 [flags, values] <- downX1 s
17 DomainMatrix index _ <- domainOf values
18 let upd val old = lambdaToFunction pat old val
19 theyDo <- doDuplicatesMatter z
20 return
21 ( "Vertical rule for mset-comprehension, ExplicitWithFlags representation"
22 , do
23 (jPat, j) <- quantifiedVar
24 let val = [essence| &values[&j] |]
25 let outBody = upd val body
26 return $ Comprehension (if theyDo then [essence| &outBody * &flags[&j] |]
27 else outBody)
28 $ gocBefore
29 ++ [ Generator (GenDomainNoRepr jPat index)
30 , Condition [essence| &flags[&j] > 0 |]
31 ]
32 ++ transformBi (upd val) gocAfter
33 )
34 theRule _ _ = na "rule_Comprehension"
35
36
37 rule_Freq :: Rule
38 rule_Freq = "mset-freq{ExplicitWithFlags}" `namedRule` theRule where
39 theRule p = do
40 (mset, x) <- match opFreq p
41 TypeMSet{} <- typeOf mset
42 MSet_ExplicitWithFlags <- representationOf mset
43 [flags, values] <- downX1 mset
44 DomainMatrix index _ <- domainOf values
45 return
46 ( "Vertical rule for mset-freq, ExplicitWithFlags representation"
47 , do
48 (iPat, i) <- quantifiedVar
49 return
50 [essence|
51 sum([ &flags[&i]
52 | &iPat : &index
53 , &values[&i] = &x
54 ])
55 |]
56 )