Skip to content

Instantly share code, notes, and snippets.

@rened
Created March 24, 2016 12:31
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 rened/de6c60570d496754ba56 to your computer and use it in GitHub Desktop.
Save rened/de6c60570d496754ba56 to your computer and use it in GitHub Desktop.
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)
@flicaflow
Copy link

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)

@rened
Copy link
Author

rened commented Mar 24, 2016

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)

@rened
Copy link
Author

rened commented Mar 24, 2016

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)

@rened
Copy link
Author

rened commented Mar 24, 2016

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