--
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.
For more options, visit https://groups.google.com/d/optout.
Just like
getBestMovie : Http String
getBestMovie = send (get “http://www.example.com/movie?best”)Shashi, lets put the WebSockets stuff in a separate thread. (WebSocket Signal a) does not mean anything to me, so I need more explanation to know if this is relevant.
In Elm, the with keyword starts a “command block”. The following value, in this case http, is a record that indicates the particular meaning of the reverse arrow (<-). In this case it means chaining asynchronous calls together.
--
I like this a lot as a lightweight, inline declaration of "OK, I'm going to work in this command context now". I was doing it already a bit by explicitly let-binding >>=.
I dislike the use of the let keyword, personally
The Haskell way relies on type classes, which Elm does not have for now.
So in Haskell, you start with a constraint like this:getBestDirector :: (Monad m) => m StringgetBestDirector = do ...
So in Haskell, you start with a constraint like this:getBestDirector :: (Monad m) => m StringgetBestDirector = do ...But that would be the wrong type, no?
Is there something I've missed in the reasoning above?
That seems to assume there's only one possible matching implementation which isn't necessarily true tho', right?
getBestDirector : Http StringgetBestDirector = with httplet movie : Stringmovie <- getBestMoviedirector : Stringdirector <- getDirector moviereturn directorI really dislike that you can't add type annotations to these things in Haskell. It also looks more like a variable assignment like in all languages (except CoffeeScript :P).
Oh but in Haskell you can! In two ways in fact:
I know I was pretty vocally negative on the original threads a few weeks ago but I like this proposal. If the heart of "thinking in Elm" is to define pure functions that then get lifted, there's something like that in using <- to unwrap the commands so that the variable have pure types. It kind of lets you think about your code as if the action happened instantaneously, or if blocking was okay.
I think return needs to be talked about a little bit, perhaps as the "simplest possible command - just return the value". I would avoid the word "trivial". Point out that it doesn't have to be the last thing that happens, like in C-style languages. That said, I like the name, and I like andThen as well. Do we have an fmap or apply for commands, or do we let signals handle those?
My concern over let is that there's no in. This makes it hard to tell where to block ends. I can only guess, but I suspect this will help both the programmer and the parser (no need to have two versions of let binding).
On the second-to-last page, you use let twice in one block. I think this is a mistake, and that let begins a block, not declares a single constant like Swift. If it's not a mistake, or if you have reasons to not use in, I'd like to hear the explanation.
Non-HTTP examples would be nice. I'm not really sure what the WebSocket comments were (another thread please) but that library should probably be rewritten as a command. That would allow you to write a node server to access databases and whatnot.
I had no idea about that! I just tried it out and got:Illegal type signature: `Int'Perhaps you intended to use -XScopedTypeVariablesSo it takes a (possibly non-standard?) language extension.
Also, does this syntax mean I can write this:do { f :: Int -> Int -> Int <- return (+) ; return (f 3 4) }I think this is not an ideal syntax, partly because of the -> <- but especially given that it clashes with the type annotation style used everywhere else.
--
Does the last line always need to be a return. What if the command is already a Command type?
I think return needs to be talked about a little bit, perhaps as the "simplest possible command - just return the value". I would avoid the word "trivial". Point out that it doesn't have to be the last thing that happens, like in C-style languages. That said, I like the name, and I like andThen as well. Do we have an fmap or apply for commands, or do we let signals handle those?
That's a good point. "return" is terrible. How about lift0 ?
--
Yield so far makes most sense to me: a computation/command yields a result.
return is associated with early termination in C, and so having it in the middle of do-block without those semantics could be troublesome. This is offset by the fact that you'll usually be assigning to something, which is weird enough to draw attention to itself. I think we shouldn't use return at the end of do-blocks in examples because it will confuse people there. They'll think it's a necessary keyword.
I strongly oppose lift0 because these new commands are separate from signals.
I could go with yield though. I'm not familiar with F# but in Python it has to do with generators and in Ruby it calls an argument block. The way to think about this is that the yielding/returning is happening immediately when the command is called, but has no effect on the control flow in the do-block. I guess I have a slight preference for yield.
Oops, here's the real link to the proposal!On Wed, Jun 4, 2014 at 7:33 AM, Evan Czaplicki <eva...@gmail.com> wrote:Here is the proposal.I tried teaching it to a JS person with no experience with ML-family languages, and it went super well! He immediately realized that it solved problems he had faced in writing atomic updates and dealing with promises that start running too soon. That it has obvious application to real life code is a really good sign!This proposal is inspired by the recent post on "The ___ Monad" and related conversations. It also draws heavily upon F#'s computation expressions which I think has a very clever way of making code look nice for imperative people. F# also shares a desire to demystify things, but I tried to simplify the language and syntax even more.
--
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.
For more options, visit https://groups.google.com/d/optout.
--
--
Something occurred to me: why even have a keyword? Is it possible to desugar the syntax without requiring an implementation of return?
--
Something occurred to me: why even have a keyword? Is it possible to desugar the syntax without requiring an implementation of return?
I think you misunderstand. I mean to say that the final statement will still have the Command type, but there is no such "class function" return. So in a Maybe command, the last command might be "Just foo", rather than " return foo"
I think you misunderstand. I mean to say that the final statement will still have the Command type, but there is no such "class function" return. So in a Maybe command, the last command might be "Just foo", rather than " return foo"
Yeah, are we going to be able to support command polymorphism? If so, yeah, you're right.
I'm much more open to return than I was earlier. The alternatives are all worse :-)
--