Skip to content

@functor for parametric constructors #40

Description

@theogf

Suppose I have a type

using Functors
struct Foo{T1,T2}
  x::T2
  Foo{T1}(x::T2) where {T1,T2} = new{T1,T2}(x)
end

Then using

@functor Foo

will not manage to capture the T1 type:

x = Foo{Real}(2.0)
y, re = Functors.functor(x)
re(y)
ERROR: MethodError: no method matching Foo(::Float64)
Stacktrace:
 [1] (::var"#5#6")(y::NamedTuple{(:x,), Tuple{Float64}})
   @ Main ~/.julia/packages/Functors/qBIlC/src/functor.jl:23
 [2] top-level scope
   @ REPL[14]:1

using

@functor Foo{T} where {T}

is not helping more

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions