never executed always true always false
    1 {-# LANGUAGE QuasiQuotes #-}
    2 
    3 module Conjure.Rules.Vertical.Set.Occurrence where
    4 
    5 import Conjure.Rules.Import
    6 
    7 
    8 rule_Comprehension :: Rule
    9 rule_Comprehension = "set-comprehension{Occurrence}" `namedRule` theRule where
   10     theRule (Comprehension body gensOrConds) = do
   11         (gocBefore, (pat, iPat, s), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
   12             Generator (GenInExpr pat@(Single iPat) s) -> return (pat, iPat, matchDefs [opToSet,opToMSet] s)
   13             _ -> na "rule_Comprehension"
   14         TypeSet{}            <- typeOf s
   15         Set_Occurrence       <- representationOf s
   16         [m]                  <- downX1 s
   17         DomainMatrix index _ <- domainOf m
   18         let i = Reference iPat Nothing
   19         return
   20             ( "Vertical rule for set-comprehension, Occurrence representation"
   21             , return $
   22                 Comprehension body
   23                     $  gocBefore
   24                     ++ [ Generator (GenDomainNoRepr pat index)
   25                        , Condition [essence| &m[&i] |]
   26                        ]
   27                     ++ gocAfter
   28             )
   29     theRule _ = na "rule_Comprehension"
   30 
   31 
   32 rule_PowerSet_Comprehension :: Rule
   33 rule_PowerSet_Comprehension = "set-powerSet-comprehension{Occurrence}" `namedRule` theRule where
   34     theRule (Comprehension body gensOrConds) = do
   35         (gocBefore, (pats, expr), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
   36             Generator (GenInExpr (AbsPatSet pats) expr) -> return (pats, expr)
   37             _ -> na "rule_PowerSet_Comprehension"
   38         -- assert pats are Single{}
   39         patNames <- forM pats $ \ pat -> case pat of Single nm -> return nm
   40                                                      _ -> na "rule_PowerSet_Comprehension: pat not s Single"
   41         s                    <- match opPowerSet expr
   42         TypeSet{}            <- typeOf s
   43         Set_Occurrence       <- representationOf s
   44         [m]                  <- downX1 s
   45         DomainMatrix index _ <- domainOf m
   46         return
   47             ( "Vertical rule for set-comprehension, Occurrence representation"
   48             , return $
   49                 Comprehension body $ concat
   50                     [ gocBefore
   51                     , concat
   52                         [ [ Generator (GenDomainNoRepr (Single pat) index)
   53                           , Condition [essence| &m[&patX] |]
   54                           ]
   55                         | pat <- take 1 patNames
   56                         , let patX = Reference pat Nothing
   57                         ]
   58                     , concat
   59                         [ [ Generator (GenDomainNoRepr (Single pat) index)
   60                           , Condition [essence| &patX > &beforeX |]
   61                           , Condition [essence| &m[&patX] |]
   62                           ]
   63                         | (before, pat) <- zip patNames (tail patNames)
   64                         , let beforeX = Reference before Nothing
   65                         , let patX = Reference pat Nothing
   66                         ]
   67                     , gocAfter
   68                     ]
   69             )
   70     theRule _ = na "rule_PowerSet_Comprehension"
   71 
   72 
   73 rule_In :: Rule
   74 rule_In = "set-in{Occurrence}" `namedRule` theRule where
   75     theRule p = do
   76         (x, s)         <- match opIn p
   77         TypeSet{}      <- typeOf s
   78         Set_Occurrence <- representationOf s
   79         [m]            <- downX1 s
   80         return
   81             ( "Vertical rule for set-in, Occurrence representation"
   82             , return $ make opIndexing m x
   83             )