JuliaDynamics / ResumableFunctions.jl

C# style generators a.k.a. semi-coroutines for Julia.
Other
158 stars 19 forks source link

`@resumable` functions do not support `where` type specifications #3

Closed gasagna closed 6 years ago

gasagna commented 6 years ago

This code

using ResumableFunctions

f(x) = 0.5*x*(x-1)

@resumable function foo(x::T) where {T}
    for i = 1:10
        @yield x
        x = f(x)
    end
    x
end

results in

ERROR: LoadError: UndefVarError: T not defined
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:576
 [2] include(::String) at ./sysimg.jl:14
 [3] process_options(::Base.JLOptions) at ./client.jl:305
 [4] _start() at ./client.jl:371
while loading ../tests.jl, in expression starting on line 32

This issue is not blocking openjournals/joss-reviews#400 to be accepted, but at least it should be mentioned in the caveats. In the long term, supporting where type specifications would be a very useful feature to have.

gasagna commented 6 years ago

I now see in the readme that parametric resumable functions are not currently supported. Apologies. This could go in the docs as well. How hard is to implement this functionality?

BenLauwens commented 6 years ago

I am waiting for a new release of Macrotools to implement this functionality. I have only to change the type definition and the constructor but this is fairly trivial once where is completely supported in Macrotools. I have added a todo section to the docs.

BenLauwens commented 6 years ago

Parametric resumable functions are available now in the master branch. Further testing is however needed.

BenLauwens commented 6 years ago

Feature is working and all tests are successful. When the docs are updated, I will do a new release and close this issue.

BenLauwens commented 6 years ago

Feature supported in v0.1.8