Skip to content

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

Open
mcabbott wants to merge 1 commit intomainfrom
mcabbott-onefunc
Open

Add @structdef MyType(fields...) method#1
mcabbott wants to merge 1 commit intomainfrom
mcabbott-onefunc

Conversation

@mcabbott
Copy link
Collaborator

@mcabbott mcabbott commented Nov 2, 2024

This is parallel to FluxML/Fluxperimental.jl#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
Copy link
Owner

CarloLucibello commented Nov 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants