-
Notifications
You must be signed in to change notification settings - Fork 28
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
Implement Effect Managers #146
Comments
I can easily see an Effect Manager being a Process on the BEAM since they communicate to the main elm 'application' via messages back and forth and all. |
@OvermindDL1 Probably the biggest one is a difference in front-end's and back-end's architecture. And although I've had some discussion with Elm's community and some of them stand for superiority of single global state, I believe it's not a way to go and Elchemy shouldn't compromise the biggest advantage of using Erlang as a platform. Obviously we could just treat internal message passing with the same restrictions as the external side effects, but I believe that could put some future great ideas to danger (namely f.i Time Travel debugging), since it's a crucial part of every Erlang system and forbidding message passing would render entire system unusable. This topic without a doubt has to be treated with extraordinary diligence and before any changes are made permanent it's worth to do as much testing as possible. Also I believe I changed my mind about following Elm's approach in here, but I still have to make my mind for sure. I believe this is a place where our roadmap should slightly skew from Elm's road and although we'll still keep consistency with all of the syntax, the implementation of Effect Managers should be handled in different manner. I'll get back to you when I discover more in terms of functional solutions to the problem. |
@OvermindDL1 WOW! Of course I agree that we still should use Algebraic Effects. I'd really love to see your suggestions on how we could achieve an explicit implementation of Algebraic Effects usage that would still conform to Elm's syntax (because elm-make) That would give us the best context to talk about explicitness, readability and easiness of entry of different solutions |
I honestly think that Elm's normal Effect Modules make Algebraic Effects quite naturally. It is a bit more verbose than the lower-level MC-OCaml (oddly enough) but it is clearer, I'd say keep them. :-) They could even transparently be turned into GenServers, or perhaps via special GenServer declarations inside the effect module. Could even do other things like supervisors or so as well, or just plain processes. Since effect modules already pass messages in and out, and the messages are well typed, then it becomes entirely safe and typed and verifiable by the Elm compiler. :-) |
I've just implemented something that might work as a type-safe GenServer. |
I'll look at it more tomorrow, but why not just use the normal |
@OvermindDL1 Exactly. The last sentence is what made me think for last couple of weeks whether all-casts is a good way to go and the longer I thought about it the less it seemed so. |
Actually an idea. You know that Elm Effects take a message as a subscription or direct call, perhaps if the first argument back is a special PID type as a return message, then it would be a call, else it would be a cast. Hmm... The current way you show is generally more powerful overall if a little verbose, can always build helpers around it in the future to fix that. :-) |
@OvermindDL1 So imagine a code like this
Where This couldn't happen in a single-threaded environment. But it definitely can on Erlang VM. Now assuming a setToTimeNow is a Not to mention how easy it is to inline multiple tasks in one process without the entire sending to
I'd like to see a similar implementation in Elm to convince me. |
Except this is not how GenServer's work. ^.^ A GenServer Remember, you can pass a pid in casts too, it is just a different internal message, hence why I say copy that style via some special types. :-) Cmd's, Tasks, and Subscriptions are emulateable in a fully concurrent manner on the BEAM. :-) |
@OvermindDL1 I might have been not clear enough about my point. What I was trying to represent is if we imagined we've got 2 GenServers talking to each other. Where one holds a state and the other one only returns Time.now. Let's call them A (state) and B (time).
If A wasn't waiting for B to return between 1. and 2. then something could send it different messages during that wait and break the atomicity of the call. //Edit |
A good read to the topic: |
Undeniably the EM is the toughest task to grasp in the entirety of Elchemy project. One of the reason being it's the most complex element of Elm, and the other that back-end isn't as domain specific and the need for different EMs might potentially be much bigger.
As the Elm-core team states: 10 EMs should be enough to cover everything that might happen from the outer world. My assumption is on backend the number might be a little higher (if finite at all)
This topic is mostly for discussion regarding what EM's might we need and whether - and if, then how - to deviate from original Elm implementation.
There might be a finite count of EM's which would be (as far from what I can think of):
With the biggest caveat being databases. Although they all operate on either HTTP, TCP or UDP it would be madness to require all of the client libraries to be rewritten in EM idiomatic style - ergo each database would probably require its own EM.
OR
We could try to write EM for Ecto. Which would be an amazing experiment
Same goes for Phoenix - or at least Plug. They probably should be wrapped too
My status right now on Effect Managers implementation - I'm afraid it has to be the same what Elm does - but we can try the hardest to provide documentation (which Elm misses for reasons) and nice templates on how to wrap existing Elixir/Erlang goodies
So far the best sources I could find on how effects work are these:
https://medium.com/@alex.lew/8e87fd14332c
And these repositories:
https://github.com/fredcy/localstorage
https://github.com/eeue56/elm-http-server/blob/master/src/HttpServer.elm
The text was updated successfully, but these errors were encountered: