never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Rules.Vertical.MSet.Occurrence where
4
5 import Conjure.Rules.Import
6
7
8 rule_Comprehension :: Rule
9 rule_Comprehension = "mset-comprehension{Occurrence}" `namedRuleZ` theRule where
10 theRule z (Comprehension body gensOrConds) = do
11 (gocBefore, (pat, s), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
12 Generator (GenInExpr pat@Single{} s) -> return (pat, s)
13 _ -> na "rule_Comprehension"
14 TypeMSet{} <- typeOf s
15 MSet_Occurrence <- representationOf s
16 [m] <- downX1 s
17 DomainMatrix index _ <- domainOf m
18 let upd val old = lambdaToFunction pat old val
19 theyDo <- doDuplicatesMatter z
20 return
21 ( "Vertical rule for mset-comprehension, Occurrence representation"
22 , do
23 (jPat, j) <- quantifiedVar
24 let val = j
25 let outBody = upd val body
26 return $ Comprehension (if theyDo then [essence| &outBody * &m[&j] |]
27 else outBody)
28 $ gocBefore
29 ++ [ Generator (GenDomainNoRepr jPat index)
30 , Condition [essence| &m[&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{Occurrence}" `namedRule` theRule where
39 theRule p = do
40 (mset, x) <- match opFreq p
41 TypeMSet{} <- typeOf mset
42 MSet_Occurrence <- representationOf mset
43 [m] <- downX1 mset
44 return
45 ( "Vertical rule for mset-freq, Occurrence representation"
46 , return [essence| &m[&x] |]
47 )