never executed always true always false
    1 {-# LANGUAGE QuasiQuotes #-}
    2 
    3 module Conjure.Rules.Vertical.Function.FunctionNDPartialDummy where
    4 
    5 import Conjure.Rules.Import
    6 
    7 
    8 rule_Image :: Rule
    9 rule_Image = "function-image{FunctionNDPartialDummy}" `namedRule` theRule where
   10     theRule [essence| image(&f,&x) |] = do
   11         Function_NDPartialDummy <- representationOf f
   12         [values] <- downX1 f
   13         toIndex <- do
   14             xTy <- typeOf x
   15             case xTy of
   16                 TypeTuple{} -> downX1 x
   17                 TypeRecord{} -> downX1 x
   18                 _ -> return [x]
   19         let valuesIndexed = make opMatrixIndexing values toIndex
   20         return
   21             ( "Function image, FunctionND representation"
   22             , return valuesIndexed
   23             )
   24     theRule _ = na "rule_Image"
   25 
   26 
   27 rule_InDefined :: Rule
   28 rule_InDefined = "function-in-defined{FunctionNDPartialDummy}" `namedRule` theRule where
   29     theRule [essence| &x in defined(&f) |] = do
   30         Function_NDPartialDummy <- representationOf f
   31         [values] <- downX1 f
   32         toIndex <- do
   33             xTy <- typeOf x
   34             case xTy of
   35                 TypeTuple{} -> downX1 x
   36                 TypeRecord{} -> downX1 x
   37                 _ -> return [x]
   38         DomainFunction _ _ _ innerDomainTo <- domainOf f
   39         let valuesIndexed = make opMatrixIndexing values toIndex
   40         let dummy = [essence| min(`&innerDomainTo`) - 1 |]
   41         return
   42             ( "Function in defined, FunctionNDPartialDummy representation"
   43             , return [essence| &valuesIndexed != &dummy |]
   44             )
   45     theRule _ = na "rule_InDefined"
   46 
   47 
   48 rule_Comprehension :: Rule
   49 rule_Comprehension = "function-comprehension{FunctionNDPartialDummy}" `namedRule` theRule where
   50     theRule (Comprehension body gensOrConds) = do
   51         (gocBefore, (pat, func), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
   52             Generator (GenInExpr pat@Single{} expr) -> return (pat, matchDefs [opToSet,opToMSet,opToRelation] expr)
   53             _ -> na "rule_Comprehension"
   54         Function_NDPartialDummy <- representationOf func
   55         DomainFunction _ _ innerDomainFr innerDomainTo <- domainOf func
   56         [values] <- downX1 func
   57         let dummy = [essence| min(`&innerDomainTo`) - 1 |]
   58         let upd val old = lambdaToFunction pat old val
   59         return
   60             ( "Mapping over a function, FunctionNDPartialDummy representation"
   61             , do
   62                 (jPat, j) <- quantifiedVar
   63                 let kRange = case innerDomainFr of
   64                         DomainTuple ts  -> Just $ map fromInt [1 .. genericLength ts]
   65                         DomainRecord rs -> Just $ map (fromName . fst) rs
   66                         _ -> Nothing
   67                     toIndex       = case kRange of
   68                                         Just ks -> [ [essence| &j[&k] |] | k <- ks ]
   69                                         Nothing -> [j]
   70                     valuesIndexed = make opMatrixIndexing values toIndex
   71                     val           = [essence| (&j, &valuesIndexed) |]
   72                 return $ Comprehension (upd val body)
   73                     $  gocBefore
   74                     ++ [ Generator (GenDomainNoRepr jPat (forgetRepr innerDomainFr))
   75                        , Condition [essence| &val[2] != &dummy |]
   76                        ]
   77                     ++ transformBi (upd val) gocAfter
   78             )
   79     theRule _ = na "rule_Comprehension"