Simplified Maybe
[ruby-do-notation.git] / README
blob9009d0c05076e29235d86ba1c8b2e03ccbb5aa91
1 Haskell-style monad do-notation for Ruby
2 ========================================
4 Example:
6     class Array
7       extend Monad
8       
9       def self.unit x
10         [x]
11       end
12       
13       def bind &f
14         map(&f).inject([]){ |a,b| a+b }
15       end
16     end
17     
18     Array.run do
19       x <- ['A', 'a']
20       y <- ['B', 'b']
21       
22       unit(x+y)
23     end
24     
25     # => ["AB", "Ab", "aB", "ab"]
27 Its biggest failing, and I don't see a way
28 out, is that you don't get lexical scope. ParseTree
29 is wonderful, but it can't work miracles.
31 You can work around it, though, by passing in
32 stuff from the outside as arguments to `run',
33 and specifying those arguments on the block
34 you pass in as well.
36 For more examples, see the test suite.
38 By Aanand Prasad (aanand.prasad@gmail.com)