JuliaDiff / JuliaDiff/ChainRulesCore.jl
Typed thunks?
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 267
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
The discussion on FluxML/Zygote.jl#966 - thunks have really evolved into monads now, right? Especially now that we're adding methods for them to lots of linear algebra and other functions. Shouldn't AbstractThunk have a type parameter, then? Kinda like
abstract type AbstractThunk{T} end
struct Thunk{T,F<:Base.Callable} <: AbstractThunk{T}
body::F
end
unthunk(t::Thunk{T}) where T = t.body()::T
Base.eltype(t::Thunk{T}) where T = T
macro thunk(body)
func = Expr(:->, Expr(:tuple), Expr(:block, __source__, body))
return quote
f = $(esc(func))
Thunk{Base._return_type(f,()), typeof(f)}(f)
end
end
thnk = let A = rand(5,5), B = rand(5,5)
@thunk A * B
end
eltype(thnk) == typeof(unthunk(thnk))
I've seen type inference fail with thunks quite a few times - maybe having typed thunks would help with that, too?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the discussion in FluxML/Zygote.jl#966 and inspect the existing AbstractThunk, Thunk, unthunk, and @thunk entry points mentioned here. Determine whether typed thunks would address the reported inference failures; done requires a settled design and a clearly agreed scope for any implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100