never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Rules.Vertical.Set.ExplicitVarSizeWithDummy where
4
5 import Conjure.Rules.Import
6
7
8 rule_Comprehension :: Rule
9 rule_Comprehension = "set-comprehension{ExplicitVarSizeWithDummy}" `namedRule` theRule where
10 theRule (Comprehension body gensOrConds) = do
11 (gocBefore, (pat, s), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
12 Generator (GenInExpr pat@Single{} s) -> return (pat, matchDefs [opToSet,opToMSet] s)
13 _ -> na "rule_Comprehension"
14 TypeSet{} <- typeOf s
15 Set_ExplicitVarSizeWithDummy <- representationOf s
16 [values] <- downX1 s
17 DomainMatrix index inner <- domainOf values
18 let dummy = [essence| max(`&inner`) |]
19 let upd val old = lambdaToFunction pat old val
20 return
21 ( "Vertical rule for set-comprehension, ExplicitVarSizeWithDummy representation"
22 , do
23 (jPat, j) <- quantifiedVar
24 let val = [essence| &values[&j] |]
25 return $ Comprehension (upd val body)
26 $ gocBefore
27 ++ [ Generator (GenDomainNoRepr jPat index)
28 , Condition [essence| &val != &dummy |]
29 ]
30 ++ transformBi (upd val) gocAfter
31 )
32 theRule _ = na "rule_Comprehension"
33
34
35 rule_PowerSet_Comprehension :: Rule
36 rule_PowerSet_Comprehension = "set-powerSet-comprehension{ExplicitVarSizeWithDummy}" `namedRule` theRule where
37 theRule (Comprehension body gensOrConds) = do
38 (gocBefore, (setPat, setPatNum, expr), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
39 Generator (GenInExpr setPat@(AbsPatSet pats) expr) -> return (setPat, length pats, expr)
40 _ -> na "rule_PowerSet_Comprehension"
41 s <- match opPowerSet expr
42 TypeSet{} <- typeOf s
43 Set_ExplicitVarSizeWithDummy <- representationOf s
44 [values] <- downX1 s
45 DomainMatrix index inner <- domainOf values
46 let dummy = [essence| max(`&inner`) |]
47 let upd val old = lambdaToFunction setPat old val
48 return
49 ( "Vertical rule for set-comprehension, ExplicitVarSizeWithDummy representation"
50 , do
51 outPats <- replicateM setPatNum quantifiedVar
52 let val = AbstractLiteral $ AbsLitSet [ [essence| &values[&j] |] | (_,j) <- outPats ]
53 return $ Comprehension (upd val body) $ concat
54 [ gocBefore
55 , concat
56 [ [ Generator (GenDomainNoRepr pat index)
57 , Condition [essence| &values[&patX] != &dummy |]
58 ]
59 | (pat,patX) <- take 1 outPats
60 ]
61 , concat
62 [ [ Generator (GenDomainNoRepr pat index)
63 , Condition [essence| &patX > &beforeX |]
64 , Condition [essence| &values[&patX] != &dummy |]
65 ]
66 | ((_, beforeX), (pat, patX)) <- zip outPats (tail outPats)
67 ]
68 , transformBi (upd val) gocAfter
69 ]
70 )
71 theRule _ = na "rule_PowerSet_Comprehension"