Created
March 24, 2016 12:31
-
-
Save rened/de6c60570d496754ba56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f(a) = a + 1 | |
g(a,f) = f(a) + 10 | |
g(1,f) | |
@code_llvm f(1) | |
@code_llvm g(1,f) | |
h(a) = f(a) + 10 | |
@code_llvm h(1) |
abstract OP <: Any
type K1 <: OP end
type K2 <: OP end
call(o::K1, a, b) = a+b
call(o::K2, a, b) = a*b
function f(o::OP,start)
Result = start
for i=1:10000
Result = o(Result,i)
end
Result
end
f(K1(), 7)
f(K2(), 7)
type K1 end
type K2 end
op(::Type{K1}, a, b) = a+b
op(::Type{K2}, a, b) = a*b
function f{T}(typ::Type{T},start)
Result = start
for i=1:10000
Result = op(typ,Result,i)
end
Result
end
@code_llvm f(K1, 7)
f(K2, 7)
type K1 end
type K2 end
call(::Type{K1}, a, b) = a+b
call(::Type{K2}, a, b) = a*b
function f{T}(op::Type{T},start)
Result = start
for i=1:10000
Result = op(Result,i)
end
Result
end
@code_llvm f(K1, 7)
f(K2, 7)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
abstract OP <: Any
type K1 <: OP
end
type K2 <: OP
end
op(o::K1, a, b) = a+b
op(o::K2, a, b) = a*b
f(o::OP,start) = begin
Result = start
for i=1:10000
Result = op(o,Result,i)
end
Result
end
f(K1(), 7)
f(K2(), 7)