Thanks again for the inputs! 
It let me to the following solution:

## -----------
module mymodule

function make_foo(f::Function)
    !method_exists(f, (Real,)) ? error("provide function with 'Real' 
argument.") : nothing

    ## create new methods
    foo(x::Real) = f(x::Real)

    function foo(x::Array)
        [foo(i/2) for i in x]'
    end

    foo
end


function bar(y, f)
        ## create foo(x::Array) and foo(x::Real) from f()
    foo = make_foo(f)

    a = length(y)
    [foo(a) foo(y)]
end

export bar

end
## -----------

using mymodule

f(x::Real) = x^2
            
bar([1:3], f)                   
## -> [9 0.25 1 2.25]

## new function
f2(x::Real) = -x

bar([1:3], f2)
## -> [-3 -.5 -1 -1.5]


Reply via email to