Skip to content

Instantly share code, notes, and snippets.

@ozra
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozra/9f5df2e0a5d8fa130dfc to your computer and use it in GitHub Desktop.
Save ozra/9f5df2e0a5d8fa130dfc to your computer and use it in GitHub Desktop.
oop + generics in crystal
abstract class QamAbstract
def initialize()
@forward–deps = [] of QamAbstract
end
end
class Qam(T) < QamAbstract
def initialize()
super()
@values = [] of T
end
end
class FooTestQam(T) < Qam(T)
end
class Mul(A, B) < Qam(A)
def initialize(a: Qam(A), b: Qam(B))
super()
@s1 = a
@s2 = b
end
end
def *(a: Qam(A), b: Qam(B))
Mul.new(a, b)
end
class Qam(T) < QamAbstract
def *(a)
Mul.new(self, a)
end
end
c–thing32 = FooTestQam(Float32).new
c–thing64 = FooTestQam(Float64).new
d–thing = Mul.new c–thing64, c–thing32
d–thing2 = c–thing32 * c–thing64
d–thing3 = d–thing * c–thing64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment