never executed always true always false
    1 module Conjure.Rules.Vertical.Relation.RelationAsMatrix where
    2 
    3 import Conjure.Rules.Import
    4 
    5 
    6 rule_Image :: Rule
    7 rule_Image = "relation-image{RelationAsMatrix}" `namedRule` theRule where
    8     theRule p = do
    9         (rel, args)         <- match opRelationImage p
   10         TypeRelation{}      <- typeOf rel
   11         Relation_AsMatrix   <- representationOf rel
   12         [m]                 <- downX1 rel
   13         let unroll = foldl (make opIndexing)
   14         return
   15             ( "relation image, RelationAsMatrix representation"
   16             , return $ unroll m args
   17             )
   18 
   19 
   20 rule_Comprehension :: Rule
   21 rule_Comprehension = "relation-comprehension{RelationAsMatrix}" `namedRule` theRule where
   22     theRule (Comprehension body gensOrConds) = do
   23         (gocBefore, (pat, rel), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
   24             Generator (GenInExpr pat@Single{} expr) -> return (pat, matchDefs [opToSet, opToMSet] expr)
   25             _ -> na "rule_Comprehension"
   26         let upd val old        =  lambdaToFunction pat old val
   27         TypeRelation{}         <- typeOf rel
   28         Relation_AsMatrix      <- representationOf rel
   29         [m]                    <- downX1 rel
   30         mDom                   <- domainOf m
   31         let (mIndices, _)      =  getIndices mDom
   32 
   33         -- we need something like:
   34         -- Q i in rel . f(i)
   35         -- Q j in (indices...) , filter(f) . f(tuple)
   36 
   37         -- let out fresh = unroll m [] (zip [ quantifiedVar fr TypeInt | fr <- fresh ] mIndices)
   38         return
   39             ( "Vertical rule for comprehension for relation domains, RelationAsMatrix representation."
   40             , do
   41                 (iPat, i) <- quantifiedVar
   42 
   43                 let lit = AbstractLiteral $ AbsLitTuple
   44                                  [ make opIndexing i (fromInt n) | n <- [1 .. genericLength mIndices] ]
   45                 let indexThis anyMatrix = make opMatrixIndexing anyMatrix
   46                                  [ make opIndexing i (fromInt n) | n <- [1 .. genericLength mIndices] ]
   47 
   48                 return $ Comprehension (upd lit body)
   49                          $  gocBefore
   50                          ++ [ Generator (GenDomainNoRepr iPat (DomainTuple mIndices))
   51                             , Condition (indexThis m)
   52                             ]
   53                          ++ transformBi (upd lit) gocAfter
   54             )
   55     theRule _ = na "rule_Comprehension"