rubyworks / platypus

Ruby Knows Types
http://rubyworks.github.com/platypus
Other
9 stars 0 forks source link

Compare Functor Project #1

Open rubyworks opened 14 years ago

rubyworks commented 14 years ago

Take a look at the "Functor" project (yea I know, terrible name for a overload system) and compare it to Platypus' implementation of method overloading.

trans commented 10 years ago

Now at https://github.com/waves/functor, but it has not seen any activity since May 2010.

trans commented 10 years ago

Besides the over use of the term "Functor" (hey, I used it first for Ruby! :tongue:) The Functor project differs syntactically in that is defines a new "def" method called "functor" to handle the creation of overloaded methods. Feature wise, it offers static value and lambda matching, which is something Patypus doesn't provide, but is should not be hard to add. Actually Platypus might support this in part, b/c the === operator is used for matching, but it was never explicitly featured. So this is definitely something it can support, and I will eventually make sure it does.

Beyond that the project has anonymous "functors", which are like Procs but have pattern matching built into them, and provide a small DSL to define them by hand. e.g.

fib = Functor.new do |f|
  f.given( Integer ) { | n | f.call( n - 1 ) + f.call( n - 2 ) }
  f.given( 0 ) { |x| 0 }
  f.given( 1 ) { |x| 1 }
end

That's kind of nice, and I wonder if Platypus can incorporate something like that into its design as well.

trans commented 10 years ago

On the other hand I just looked at the code (https://github.com/waves/functor/blob/master/lib/functor.rb) and my eyes went cross.