kotovalexarian / typeclass.rb

Haskell type classes in Ruby.
MIT License
6 stars 1 forks source link

Deal with dynamic method dispatch #27

Closed ghost closed 8 years ago

ghost commented 8 years ago

This code can behave differently in cases if it was optimized or not. Typeclass can be frozen, so we can make assumptions about it's functions. The problem concerns to infix functions.

Foo = Typeclass.new :a do
  infix :foo, [:a]
end

class A
end

Foo.instance A do
  def foo(this)
    foo this # some recursion
  end
end

class B < A
  def foo
    fail # some unexpected behavior
  end
end

http://www.sitepoint.com/rubys-important-hook-methods/ http://stackoverflow.com/questions/708642/how-to-make-a-base-class-method-non-overridable-in-ruby http://scie.nti.st/2008/9/17/making-methods-immutable-in-ruby/ http://stackoverflow.com/questions/2441524/closest-ruby-representation-of-a-private-static-final-and-public-static-final https://www.ruby-forum.com/topic/65458

ghost commented 8 years ago

Infix functions won't be instance methods (see #25)