| | 56 | === Examples === |
| | 57 | |
| | 58 | Some translation examples (using the do notation): |
| | 59 | |
| | 60 | {{{ |
| | 61 | [ x+y | x <- Just 1, y <- Just 2 ] |
| | 62 | |
| | 63 | => |
| | 64 | |
| | 65 | do x <- Just 1 |
| | 66 | y <- Just 2 |
| | 67 | return (x+y) |
| | 68 | }}} |
| | 69 | |
| | 70 | Transform statements: |
| | 71 | |
| | 72 | {{{ |
| | 73 | [ x | x <- [1..], then take 10 ] |
| | 74 | |
| | 75 | => |
| | 76 | |
| | 77 | take 10 (do |
| | 78 | x <- [1..] |
| | 79 | return x) |
| | 80 | }}} |
| | 81 | |
| | 82 | Grouping statements (note the change of types): |
| | 83 | |
| | 84 | {{{ |
| | 85 | [ (x :: [Int]) | x <- [1,2,1,2], then group by x ] :: [[Int]] |
| | 86 | }}} |
| | 87 | |
| | 88 | Parallel statements: |
| | 89 | |
| | 90 | {{{ |
| | 91 | [ x+y | x <- [1,2,3] |
| | 92 | | y <- [4,5,6] ] |
| | 93 | |
| | 94 | => |
| | 95 | |
| | 96 | do (x,y) <- mzip [1,2,3] [4,5,6] |
| | 97 | return (x+y) |
| | 98 | }}} |
| | 99 | |