-
Notifications
You must be signed in to change notification settings - Fork 140
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
[eta] Annotations and ADT foreign export #601
Comments
Thanks for the beautiful write-up, @NickSeagull! I agree, this looks quite feasible. I made the following edits to your original issue:
|
I might start working on this, what would be the first steps to work on this @rahulmutt ? Also, could you assign this to me please? 😄 |
Also, I saw that the |
@NickSeagull Yes, the java annotation declaration was made keeping in mind that we'd eventually support annotations for exports. Right now that is used for parsing the The general idea of how to go about implementing this:
|
By the way you should parse annotations exactly like Java does (keeps things consistent): https://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html |
Disregard this entire comment. Because annotations are only relevant for foreign exports, you need only extend the |
Great, thanks! 😄 |
I've started working on this. I've implemented:
@Controller
@RequestMapping "/"
data PostController = PostController
{ @Autowired postRepository :: PostRepository
}
@GetMapping "/"
posts :: Model -> Java PostController String
posts model = do
posts <- postRepository <.> findAll
model <.> addAttribute "posts" posts
return "postList"
@PostMapping "/"
addToPostsList :: Post -> Java PostController String
addToPostsList post = do
postRepository <.> save post
return "redirect:/" Remaining steps:
|
Any progress on this? Looking forward to it. |
No unfortunately. Thanks for showing interest though, I'll pin this issue to indicate that it has priority. |
There are many frameworks that depend on annotations. I will be using Spring Boot as an example.
Spring Boot is a widespread Java framework that does not enforce any kind of structure, while being able to use all the Spring Boot modules to make application development easier.
These modules include interoperability with:
The problem here is, Spring Boot is mainly annotation driven. And while we are able to do dependency injection using a custom environment (like a
ReaderT
), other features of the framework are not accessible because of its hard dependency on annotations.Of course, one can use the Java Persistence API (JPA) to handle the creation and modification of database entries.
Example application
This is an example of a very simple Spring Boot application that handles persistence and routing:
I'll be using Scala as the example language just for the sake of brevity, as it is less verbose and it is directly translatable to Java.
Application.scala
This is the entry point of our application. We are passing
Application.class
to therun
method so Spring can operate on it using reflection.I can imagine doing this easily in Eta:
Post.scala
This class defines an entity that will be stored in the
Post
table.I think it would be quite tricky to do so, unless we force the exported ADTs to be records:
(Idea: non-records fields could be exported as
_1
,_2
,_n
)PostRepository.scala
This is just an interface that allows us to use some methods to access our database:
(Note: I'm not sure if this is the correct way to do so)
PostController.scala
This is the biggest part, the controller that handles all the requests and uses the other classes
It looks quite feasible to me.
Note: I'm not an expert in the Eta export features. Although I'm a Haskeller, I haven't used Eta too much :)
**Note 2: This are just snippets of code, if the whole project is needed, you can find it in this repository, this commit **
The text was updated successfully, but these errors were encountered: