Changes between Version 4 and Version 5 of MonadComprehensions
- Timestamp:
- 05/12/11 03:09:05 (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MonadComprehensions
v4 v5 56 56 === Examples === 57 57 58 Some translation examples (using the do notation):58 Some translation examples using the do notation to avoid things like pattern matching failures are: 59 59 60 60 {{{ 61 61 [ x+y | x <- Just 1, y <- Just 2 ] 62 62 63 => 64 63 -- translates to: 65 64 do x <- Just 1 66 65 y <- Just 2 … … 73 72 [ x | x <- [1..], then take 10 ] 74 73 75 => 76 74 -- translates to: 77 75 take 10 (do 78 76 x <- [1..] … … 84 82 {{{ 85 83 [ (x :: [Int]) | x <- [1,2,1,2], then group by x ] :: [[Int]] 84 85 -- translates to: 86 do x <- mgroupWith (\x -> x) [1,2,1,2] 87 return x 86 88 }}} 87 89 … … 92 94 | y <- [4,5,6] ] 93 95 94 => 95 96 -- translates to: 96 97 do (x,y) <- mzip [1,2,3] [4,5,6] 97 98 return (x+y) 98 99 }}} 99 100 101 Note that the actual implementation is **not** using the *do*-Notation 102 100 103 == Implementation details == 104 105 Monad comprehensions had to change the `StmtLR` data type in the `hsSyn/HsExpr.lhs` file in order to be able to lookup and store all functions required to desugare monad comprehensions correctly (e.g. `return`, `(>>=)`, `guard` etc). Renaming is done in `rename/RnExpr.lhs` and typechecking in `typecheck/TcMatches.lhs`. The main desugaring is done in `deSugar/DsListComp.lhs`. If you want to start hacking on monad comprehensions I'd look at those files first. 106 107 Some things you might want to be aware of: 108 109 [todo]
