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