| 5 | {{{ |

| 6 | Variables : x and y |

| 7 | Expressions : e, f and g |

| 8 | Patterns : w |

| 9 | Qualifiers : p, q and r |

| 10 | }}} |

| 11 | |

| 12 | The main translation rule for monad comprehensions. |

| 13 | |

| 14 | {{{ |

| 15 | [ e | q ] = [| q |] >>= (return . (\q_v -> e)) |

| 16 | }}} |

| 17 | |

| 18 | `(.)_v` rules. Note that `_v` is a postfix rule application. |

| 19 | |

| 20 | {{{ |

| 21 | (w <- e)_v = w |

| 22 | (let w = d)_v = w |

| 23 | (g)_v = () |

| 24 | (p , q)_v = (p_v,q_v) |

| 25 | (p | v)_v = (p_v,q_v) |

| 26 | (q, then f)_v = q_v |

| 27 | (q, then f by e)_v = q_v |

| 28 | (q, then group by e using f)_v = q_v |

| 29 | (q, then group using f)_v = q_v |

| 30 | }}} |

| 31 | |

| 32 | `[|.|]` rules. |

| 33 | |

| 34 | {{{ |

| 35 | [| w <- e |] = e |

| 36 | [| let w = d |] = return d |

| 37 | [| g |] = guard g |

| 38 | [| p, q |] = ([| p |] >>= (return . (\p_v -> [| q |] >>= (return . (\q_v -> (p_v,q_v)))))) >>= id |

| 39 | [| p | q |] = mzip [| p |] [| q |] |

| 40 | [| q, then f |] = f [| q |] |

| 41 | [| q, then f by e |] = f (\q_v -> e) [| q |] |

| 42 | [| q, then group by e using f |] = (f (\q_v -> e) [| q |]) >>= (return . (unzip q_v)) |

| 43 | [| q, then group using f |] = (f [| q |]) >>= (return . (unzip q_v)) |

| 44 | }}} |

| 45 | |

| 46 | `unzip (.)` rules. Note that `unzip` is a desugaring rule (i.e., not a function to be included in the generated code). |

| 47 | |

| 48 | {{{ |

| 49 | unzip () = id |

| 50 | unzip x = id |

| 51 | unzip (w1,w2) = \e -> ((unzip w1) (e >>= (return .(\(x,y) -> x))), (unzip w2) (e >>= (return . (\(x,y) -> y)))) |

| 52 | }}} |

| 53 | |