Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically parameterize types #85

Open
greimel opened this issue Oct 8, 2018 · 3 comments
Open

Automatically parameterize types #85

greimel opened this issue Oct 8, 2018 · 3 comments

Comments

@greimel
Copy link

greimel commented Oct 8, 2018

On discourse, I asked for a way to automatically parameterize types with a macro.

@parameterize struct Foo
   field1::Number
   field2::AbstractVector
   field3
end

yields

struct Foo{T1 <: Number, T2 <: AbstractVector, T3}
   field1::T1
   field2::T2
   field3::T3
end

@mohamed82008 provided the solution for this. It was suggested to add such functionality to this package. Potentially playing out nicely with @with_kw.

@Datseris
Copy link

Datseris commented Oct 8, 2018

In the discourse post it was mentioned that this functionality exists in QuickTypes. However, I don't think that matters. I think it is a great idea to add it to Parameters. There should be one great package that has all the good features.

@mohamed82008
Copy link

My solution has some unhandled corner cases, mostly related to bad type definitions, like an integer showing up or something like that. Should be easy to fix though. Also inner constructors are not supported and not sure how well it can play with @with_kw since I haven't read the latter. So it will probably be more than a copy-paste PR.

@mauro3
Copy link
Owner

mauro3 commented Nov 23, 2019

I think the syntax ought to be

@parameterize struct Foo
   field1<:Number
   field2<:AbstractVector
   field3<:Any
end

to not break existing code.

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

No branches or pull requests

4 participants