CarloLucibello / AutoStructs.jl

Compact struct definition and prototyping
MIT License
3 stars 0 forks source link

Add `@structdef MyType(fields...)` method #1

Open mcabbott opened 3 days ago

mcabbott commented 3 days ago

This is parallel to https://github.com/FluxML/Fluxperimental.jl/pull/24 in that it adds a "method" to the macro which does this:

julia> @structdef Store(some::Vector, things)
var"##Store#564"

That is, it makes a re-definable struct, with just the default constructor. That seems perhaps more broadly what you would want first, outside of Flux.

Whether this is the ideal notation I don't know. It could also be

@def struct Store
    some::Vector
    things
end

But that's a much bigger deviation from existing code, and maybe looks more like you have forgotten type parameters.

Needs tests.

CarloLucibello commented 3 days ago

yes, it would be nice to match @kwdef features but with concrete types and prototypable.

I like more the

@def struct Store
    some::Vector
    things
end

notation, which can be replaced by @concrete @kwdef struct Store after prototyping is done.

Maybe out of scope for this package, but this could be the foundation of a pydantic-like package.