Git Product home page Git Product logo

Comments (6)

Randgalt avatar Randgalt commented on August 16, 2024

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.

Alex-At-Home avatar Alex-At-Home commented on August 16, 2024

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.

Randgalt avatar Randgalt commented on August 16, 2024

So, in the monad example, would the StateExample container extend StateExample? Maybe it should be an option in @TypeContainer.

from soabase-halva.

Alex-At-Home avatar Alex-At-Home commented on August 16, 2024

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.

Randgalt avatar Randgalt commented on August 16, 2024

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.

Alex-At-Home avatar Alex-At-Home commented on August 16, 2024

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:

  1. you'd be forced to create your own ExampleTypes_, containing the "local" data model, and then Example with the logic, importing the generated ExampleTypes (and not having the definitions local)
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.