No new thinking on that as far as I'm aware...what are you looking to build?
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/nuR4NnCVcMs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So now, either I write a ports for commonmark.js, or I write it as a native module. I asked about it here with no answers.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
The thing about ports for something like this is it feels a bit unnatural to invoke the port resulting in a Cmd. Then you'll need a subscription port to get the result back in, and have that pass it to your update function from where you can take it and place it in the model. That doesn't feel like a good way to call a function : String -> Ast.I'd say the best solution is to implemented your parser in pure Elm. But if that is too much work, just hack together a native module that calls out to commonmark.js. You won't be able to publish your native module to elm packages, but that's ok, perhaps no-one else really wants your markdown with embedded SQL anyway, and if they do there is always elm-github-install. Some time down the road when you really need to share this amazing library, redo it in pure Elm.
Would it help if there were a standard mechanism to invoke JavaScript code as a task (or equivalently to make JavaScript code available as a task)?
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
Dne středa 7. prosince 2016 17:18:37 UTC+1 Mark Hamburg napsal(a):Would it help if there were a standard mechanism to invoke JavaScript code as a task (or equivalently to make JavaScript code available as a task)?
Yes! Very much! If this happened, I'd definitely revisit the decision to leave Elm.
So now, either I write a ports for commonmark.js, or I write it as a native module. I asked about it here with no answers.I think if you write it as ports or native, you'll still need to map the AST between javascript and Elm. As a native module that could be done with a Decoder or by constructing the Elm AST in native code with Javascript. Perhaps Decoders are not so bad?
I don't think a parser is a side-effect. A parser is a pure function from String -> Ast, with no side effects.
The thing about ports for something like this is it feels a bit unnatural to invoke the port resulting in a Cmd. Then you'll need a subscription port to get the result back in, and have that pass it to your update function from where you can take it and place it in the model. That doesn't feel like a good way to call a function : String -> Ast.
This resonates with me very much. This is _exactly_ the reason why I made The Elm Alienation post on Reddit: https://www.reddit.com/r/elm/comments/5g3540/the_elm_alienation/
On Thursday, December 8, 2016 at 5:27:53 PM UTC, Vojtěch Král wrote:This resonates with me very much. This is _exactly_ the reason why I made The Elm Alienation post on Reddit: https://www.reddit.com/r/elm/comments/5g3540/the_elm_alienation/If I can quote from that: "In a nutshell, Elm needs unsafe."I mostly agree with this, but have some reservations.The existing native API is easy enough to figure out, just look at any 'native' module implementation. Basically you follow the conventions you see for namespaing you javascript code and wrapping functions with helpers like F2, F3 and so on, and return an object containing all the functions you want to expose to Elm.Also code does not need to be made asynchronous to be made type-safe, you could use Result for synchronous calls. Just map all exceptions to Err, and succesfull calls to Ok.It would be nice if we could just mark our own native modules as 'unsafe' and have an 'unsafe' section on package.elm-lang.org to share them.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
operations that need to deal with the external world
While there are certainly times when synchronous calls would have been nice, I recognize that having synchronous behavior for potentially mutable external state also tends to imply a lot about execution order — something that a pure functional language expects to be more free about. Hence, I think it's reasonable to force operations that need to deal with the external world to be asynchronous.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
One doesn't need them to be asynchronous but making them asynchronous helps reinforce the notion that this is happening outside the Elm universe. And if you want monads, Elm's tasks are monadic.
the elm package repo would very quickly get poluted with js code that causes runtime exceptions
the elm package repo would very quickly get poluted with js code that causes runtime exceptionsBut, Tasks have error handling built into them. We could do something similar with synchronous code, just catch any exceptions thrown, and treat the value in Elm as something like a Result.
--
the elm package repo would very quickly get poluted with js code that causes runtime exceptionsBut, Tasks have error handling built into them. We could do something similar with synchronous code, just catch any exceptions thrown, and treat the value in Elm as something like a Result.
Sure, I could abuse it to call a stateful js ap
--
I would love to be able to make synchronous functional calls to js and get a Result back.
Sure, I could abuse it to call a stateful js apWhich you can currently do with Cmd ports! We'd just want to wrap it in some type like Task or Cmd, and then it would be nicely segregated from pure code.
"Sure, I could call supposedly pure js code to compute a value, but that js happens to have some unintended side effect or stateful behavior, causing problem if the Elm compiler ...".
On Wed, Dec 14, 2016 at 10:00 AM, Desmond D'Souza <des...@dsouzaville.com> wrote:
I would love to be able to make synchronous functional calls to js and get a Result back.Taking simple clean synchronous functional code (e.g. if it were all in Elm), and being forced to chop out bits into async calls with async Msg callbacks (just because it is not all in Elm) impacts my code in unpleasant ways:
- weird async bugs: will my originally sync call to layout(graph) get the layout answer back after the user has switched to another graph?
- pollution of model and update:
- I need to stuff into my model bits that were simple transient local variables before, and maintain those extra bits everywhere in my code. Forget to clear them somewhere, and chunks of my code like another update branch or a view function, think I have a current graph waiting for a layout.
- I add more checks into my update to deal with possibly getting intervening unrelated async inputs
- API bloat: why does AndHereIsYourLayoutBack need to be part of my API, when that is already explicit through the outgoing call mechanism (e.g. via something like a synchronous port, or some alternative)
I think #1 would be somewhat alleviated by synchronous tasks from this thread, but #2 and #3 remain.Properly supporting this use case would be good for Elm. Sure, I could abuse it to call a stateful js api, causing problems if the Elm compiler moves expression evaluation order around, hence I use some unsafe marker either as an annotation to myself or to the compiler.On Wednesday, December 14, 2016 at 4:48:06 AM UTC-6, Rupert Smith wrote:
On Tuesday, December 13, 2016 at 3:42:23 PM UTC, Joey Eremondi wrote:the elm package repo would very quickly get poluted with js code that causes runtime exceptionsBut, Tasks have error handling built into them. We could do something similar with synchronous code, just catch any exceptions thrown, and treat the value in Elm as something like a Result.> the elm package repo would very quickly get poluted with js code that causes runtime exceptions _* and is not portable *_Result would work, but the not portable bit is equally impoertant.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
On Wednesday, December 14, 2016 at 6:00:14 PM UTC, Desmond D'Souza wrote:I would love to be able to make synchronous functional calls to js and get a Result back.Would you want to publish this code to elm-package?
Would the javascript your package calls be included in the package?
--
15 dec. 2016 kl. 18:40 skrev Mark Hamburg <mhamb...@gmail.com>:Having external compute run asynchronously opens the possibility of having it run in parallel some day.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
sticking it into a monad does not make it any more reasonable
15 dec. 2016 kl. 19:27 skrev Joey Eremondi <joey.e...@gmail.com>:sticking it into a monad does not make it any more reasonableThe thing is, it's not about calling unreasonable code, it's about calling *potentially* unreasonable code.
Putting it in a Monad doesn't make it more reasonable, but it means that the reasonability of pure Elm code is not compromised, and unreasonable JS can't make Elm behave in an unreasonable way.
And making it return a Result (or similar, like Task's error type) ensures that the uses of this code *must* handle any unreasonably that occurs.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
Again wrong: just having a certain type does not enable client code to handle the fallout—because the effects of JS code are literally arbitrary. The only achieved effect is that the fallout is signaled in the type system. But then if most of the code is reasonable despite being JS, most people will just run these Tasks as if they’re fine anyway, and the function of the type marker is lost—it just makes life a little more miserable where people are forced to jump through hoops.
I was talking about this further with my coworkers and we more or less agreed that the key things that could help with Elm's interface to JavaScript were:* Task ports. Tasks are a building block in a way that commands are not. Forcing all external interactions to be asynchronous makes it more clear that one is stepping outside and code could fail.* A "foreign" value type that could capture a reference coming from JavaScript to be handed back in other calls. For example, though not a great JavaScript example, this could be a database connection. All operations on the database would occur via tasks. We just need an easy way for Elm to hold the handle to the database connection. This functionality would be better if the foreign types could be distinguished within Elm in their declaration — e.g.port type DBConnection("port" reads wrong but I was avoiding introducing a new keyword.)That said, one could also just use Foreign as a base type and use Elm code wrap it in more meaning for the type checker:type DBConnection = DBConnection ForeignThis, however, probably makes it harder to use the types safely in the task APIs.Would those two features address everything needed? No. In particular, port wireup inhibits creating libraries. But it would make it much more straightforward for any individual project to build interfaces to JavaScript-based functionality.Mark
On Thu, Dec 8, 2016 at 9:27 AM Vojtěch Král <vojtechkr...@gmail.com> wrote:
Dne úterý 6. prosince 2016 23:14:06 UTC+1 Rupert Smith napsal(a):
The thing about ports for something like this is it feels a bit unnatural to invoke the port resulting in a Cmd. Then you'll need a subscription port to get the result back in, and have that pass it to your update function from where you can take it and place it in the model. That doesn't feel like a good way to call a function : String -> Ast.
I'd say the best solution is to implemented your parser in pure Elm. But if that is too much work, just hack together a native module that calls out to commonmark.js. You won't be able to publish your native module to elm packages, but that's ok, perhaps no-one else really wants your markdown with embedded SQL anyway, and if they do there is always elm-github-install. Some time down the road when you really need to share this amazing library, redo it in pure Elm.
This resonates with me very much. This is _exactly_ the reason why I made The Elm Alienation post on Reddit: https://www.reddit.com/r/elm/comments/5g3540/the_elm_alienation/
I also wanted to ask here about the status of the Native API but I'm seeing you guys already inquired.
Forcing people to rewrite everything in Elm is a terrible idea.
Dne středa 7. prosince 2016 17:18:37 UTC+1 Mark Hamburg napsal(a):
Would
it help if there were a standard mechanism to invoke JavaScript code as
a task (or equivalently to make JavaScript code available as a task)?
Yes! Very much! If this happened, I'd definitely revisit the decision to leave Elm.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
I don't see how refactoring my Model, Msg, update in order to use an async Task / Cmd + Msg callback is a better choice, specially since I would want to know if things went wrong on the js side anyway.