Changes between Version 1 and Version 2 of MonadComprehensions


Ignore:
Timestamp:
Apr 29, 2011 7:43:40 PM (4 years ago)
Author:
nsch
Comment:

translation rules tacken from the #4370 ticket

Legend:

Unmodified
Added
Removed
Modified
  • MonadComprehensions

    v1 v2  
    33== Translation rules ==
    44
     5{{{
     6Variables    : x and y
     7Expressions  : e, f and g
     8Patterns     : w
     9Qualifiers   : p, q and r
     10}}}
     11
     12The 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{{{
     49unzip () = id
     50unzip x  = id
     51unzip (w1,w2) = \e -> ((unzip w1) (e >>= (return .(\(x,y) -> x))), (unzip w2) (e >>= (return . (\(x,y) -> y))))
     52}}}
     53
    554== Implementation details ==