descriptionHaskell-style do-notation for Ruby
owneraanand.prasad@gmail.com
last changeFri, 15 Feb 2008 11:38:45 +0000 (15 11:38 +0000)
content tags
add:
readme

Haskell-style monad do-notation for Ruby

Example:

class Array
  extend Monad

  def self.unit x
    [x]
  end

  def bind &f
    map(&f).inject([]){ |a,b| a+b }
  end
end

Array.run do
  x <- ['A', 'a']
  y <- ['B', 'b']

  unit(x+y)
end

# => ["AB", "Ab", "aB", "ab"]

Its biggest failing, and I don't see a way out, is that you don't get lexical scope. ParseTree is wonderful, but it can't work miracles.

You can work around it, though, by passing in stuff from the outside as arguments to `run', and specifying those arguments on the block you pass in as well.

For more examples, see the test suite.

By Aanand Prasad (aanand.prasad@gmail.com)

shortlog
2008-02-15 Aanand PrasadSimplified Maybemaster
2008-02-04 Aanand PrasadTweaked spec syntax
2008-02-04 Aanand PrasadAdded default rake task
2008-02-04 Aanand PrasadTweaked README
2008-02-04 Aanand PrasadRemoved .tmproj
2008-01-14 Aanand PrasadNow uses arrows!!
2008-01-12 Aanand PrasadRSpec-ified
2008-01-12 Aanand PrasadInitial commit
heads
16 years ago master