Comments (6)
In the generated class, the Aliases/Cases, etc. would still be "static" classes, right? i.e. you don't need to instantiate the container class.
from soabase-halva.
I don't know what else I want to do in/with the container class (ie it's not just a container, it's also the namespace for all my logic - that's important because that's what lets me keep the case classes and type aliases "local" in a natural way), so I don't want to restrict what I do with it, all I know is that I want to declare Halva artefacts inside it and have them appear in (eg) MyClassName
+Types
So eg two examples:
- I just want a central "library" class containing all my types - in which case an interface is fine
- Eg the State monad example - the type alias is a tiny part of that
from soabase-halva.
So, in the monad example, would the StateExample container extend StateExample? Maybe it should be an option in @TypeContainer
.
from soabase-halva.
The way I'd like to write the actual code looks something like this:
package oh.hai;
import oh.hai.ExampleTypes.Stack;
import static oh.hai.ExampleTypes.Stack.Stack;
import oh.hai.ExampleTypes.Point;
import static oh.hai.ExampleTypes.Point.Point;
//...
@TypeContainer(suffix="Types", unsuffix="")
public class Example {
@TypeAlias(suffix="", unsuffix="Alias") interface StackAlias extends ConsList<Stack> {}
@CaseClass(suffix="", unsuffix="Alias") interface PointAlias { double x(); double y(); }
// Business logic
int main(String[] args) {
// Eg
final Stack s = Stack(List(1, 2, 3));
final Point p = Point(1.0, 1.0);
}
}
So although the code is going into a different class (ExampleTypes vs Example), as a developer everything looks like it's local, someone in a different class can happily declare Stack
to be ArrayList<String>
, etc.
from soabase-halva.
In your example above, the generated class would be ExampleTypes
. So, should all the methods, etc. in Example be copied into ExampleTypes
or should ExampleTypes
extend Example
? What's clumsy is that main() expects the generated types to exist but they won't exist until processing. After processing, main() would have to Reference (or have a static import for) ExampleTypes.Stack or something similar.
from soabase-halva.
Hmm interesting, having used now @TypeContainer
a bit more I see what you mean.
Seems like there are two ways of doing it, neither of which is great:
- you'd be forced to create your own
ExampleTypes_
, containing the "local" data model, and then Example with the logic, importing the generatedExampleTypes
(and not having the definitions local) - or you write your case classes etc at the top of
Example
, hit rebuild, and then go write the logic, which is kinda ugly but not a million miles different from creating the data model in a separate file and hitting rebuild? (and then you get the data model visible locally)
I feel like some people are going to prefer 1 and some 2?
(In the latter case, ExampleTypes
doesn't inherit from Example
, it's linked to Example
only by the common name stem)
(Do you ever want to inherit the generated container? It's not like you can use the declared versions of anything anyway, you always use the generated ones, no?)
from soabase-halva.
Related Issues (20)
- More thoughts on pattern matching syntax
- Fix documentation re type aliases HOT 1
- Support type aliases of concrete types, constructor overrides, co-variant returns HOT 4
- TypeAliases - a few more issues/thoughts from using it HOT 3
- Support generated values inside of generated classes
- Have simpler Consable<T> interface?
- Should (can?) type aliases also "override" the static members to "fix" the return type HOT 3
- Use enums for case objects HOT 1
- MonadicFor annotation can generate NPE HOT 7
- Support command line overrides for Annotation attributes
- Review Type Safety - Pattern/Extraction is currently loosely typed. Make it strongly typed without (hopefully) losing usability HOT 1
- Think about supporting Bean Validation 1.1 annotations on fields HOT 3
- Add debug tools
- Support extracted/multi-assignment
- Add support for dsl-json HOT 2
- CaseClasses that extend interfaces not working properly
- Halva annotation retentions should be RUNTIME HOT 1
- Halva annotations must appear first
- CaseClass mis-generates wildcard types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soabase-halva.