-
Notifications
You must be signed in to change notification settings - Fork 64
Open
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?
Metadata
Metadata
Assignees
Labels
No labels