never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Rules.Vertical.Partition.Occurrence where
4
5 import Conjure.Rules.Import
6
7
8 rule_Comprehension :: Rule
9 rule_Comprehension = "partition-comprehension{Occurrence}" `namedRule` theRule where
10 theRule (Comprehension body gensOrConds) = do
11 (gocBefore, (pat, expr), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
12 Generator (GenInExpr pat@Single{} expr) -> return (pat, matchDefs [opToSet, opToMSet] expr)
13 _ -> na "rule_Comprehension"
14 let partition_ = matchDef opParts expr
15 TypePartition{} <- typeOf partition_
16 DomainPartition _ _ innerDomain <- domainOf partition_
17 Partition_Occurrence <- representationOf partition_
18 [numPartsVar, whichPart, _partSizesVar, _firstIndexVar] <- downX1 partition_
19 indexDom <- forgetRepr <$> domainOf numPartsVar
20 let upd val old = lambdaToFunction pat old val
21 return
22 ( "Vertical rule for partition-comprehension, Occurrence representation"
23 , do
24 (pPat, p) <- quantifiedVar
25 (kPat, k) <- quantifiedVar
26 -- the value, a set representing part number p
27 -- indicate that there won't be duplicates in this comprehension!
28 let val = make opToSetWithFlag True $ Comprehension k
29 [ Generator (GenDomainNoRepr kPat innerDomain)
30 , Condition [essence| &whichPart[&k] = &p |]
31 ]
32 return $ Comprehension (upd val body)
33 $ gocBefore
34 ++ [ Generator (GenDomainNoRepr pPat indexDom) -- part number p
35 , Condition [essence| &p <= &numPartsVar |]
36 ]
37 ++ transformBi (upd val) gocAfter
38 )
39 theRule _ = na "rule_Comprehension"