never executed always true always false
1 {-# LANGUAGE QuasiQuotes #-}
2
3 module Conjure.Rules.Vertical.Function.Function1D where
4
5 import Conjure.Rules.Import
6
7
8 rule_Comprehension :: Rule
9 rule_Comprehension = "function-comprehension{Function1D}" `namedRule` theRule where
10 theRule (Comprehension body gensOrConds) = do
11 (gocBefore, (pat, func), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
12 Generator (GenInExpr pat@Single{} expr) -> return (pat, matchDefs [opToSet,opToMSet,opToRelation] expr)
13 _ -> na "rule_Comprehension"
14 Function_1D <- representationOf func
15 TypeFunction{} <- typeOf func
16 DomainFunction _ _ index _ <- domainOf func
17 [values] <- downX1 func
18 let upd val old = lambdaToFunction pat old val
19 return
20 ( "Mapping over a function, Function1D representation"
21 , do
22 (jPat, j) <- quantifiedVar
23 let valuesIndexed = [essence| (&j, &values[&j]) |]
24 return $ Comprehension
25 (upd valuesIndexed body)
26 $ gocBefore
27 ++ [Generator (GenDomainNoRepr jPat (forgetRepr index))]
28 ++ transformBi (upd valuesIndexed) gocAfter
29 )
30 theRule _ = na "rule_Comprehension"
31
32
33 rule_Comprehension_Defined :: Rule
34 rule_Comprehension_Defined = "function-comprehension_defined{Function1D}" `namedRule` theRule where
35 theRule (Comprehension body gensOrConds) = do
36 (gocBefore, (pat, expr), gocAfter) <- matchFirst gensOrConds $ \ goc -> case goc of
37 Generator (GenInExpr pat@Single{} expr) -> return (pat, expr)
38 _ -> na "rule_Comprehension"
39 func <- match opDefined expr
40 Function_1D <- representationOf func
41 DomainFunction _ _ index _ <- domainOf func
42 let upd val old = lambdaToFunction pat old val
43 return
44 ( "Mapping over a function, Function1D representation"
45 , do
46 (jPat, j) <- quantifiedVar
47 let val = j
48 return $ Comprehension (upd val body)
49 $ gocBefore
50 ++ [ Generator (GenDomainNoRepr jPat (forgetRepr index)) ]
51 ++ transformBi (upd val) gocAfter
52 )
53 theRule _ = na "rule_Comprehension_Defined"
54
55
56 rule_Image :: Rule
57 rule_Image = "function-image{Function1D}" `namedRule` theRule where
58 theRule [essence| image(&func,&x) |] = do
59 Function_1D <- representationOf func
60 TypeFunction{} <- typeOf func
61 [values] <- downX1 func
62 return
63 ( "Function image, Function1D representation"
64 , return [essence| &values[&x] |]
65 )
66 theRule _ = na "rule_Image"