evancz/elm-architecture-tutorial

Explain (=>) = (,)

jonoabroad opened this issue ยท 19 comments

I assume it is an alias being used to create div styles.

It expands out to this definition:

(=>) a b =
  (a, b)

So when you say "abc" => 123 it is the same as ("abc", 123).

Where did you first see this, and where would you recommend putting a note about it? I believe it is used in many places. I need to know your particular experience to add hints in a targeted and helpful way.

It's first mentioned in example five RandomGif.elm.

I think a comment in the code would be enough, possibly including a link to
the appropriate source documentation.

My experience was "I'm unsure what this means, I assume it is a very short
alias or macro."

As an aside, I tried it in the REPL and got the following error:

(=>) a b = (a,b)

ERRORS in repl-temp-000.elm

#################################################

-- SYNTAX PROBLEM --------------------------------------------
repl-temp-000.elm

I ran into something unexpected when parsing your code!

4| =>

 ^

I am looking for one of the following things:

an expression

whitespace

On 16 November 2015 at 23:27, Evan Czaplicki notifications@github.com
wrote:

It expands out to this definition:

(=>) a b =
(a, b)

So when you say "abc" => 123 it is the same as ("abc", 123).

Where did you first see this, and where would you recommend putting a note
about it? I believe it is used in many places. I need to know your
particular experience to add hints in a targeted and helpful way.

โ€”
Reply to this email directly or view it on GitHub
#40 (comment)
.

I've just found the following in the noreadink html widgets repo:

{- Convenience for making tuples. Looks nicer in conjunction with
classList. -}
(=>) : a -> b -> (a, b)
(=>) =
(,)

Possibly:

(=>) = (,)

-- This expands out to this definition:
-- (=>) : a -> b -> (a, b)
-- (=>) a b =
-- (a, b)
-- So when you say "abc" => 123 it is the same as ("abc", 123).

Scream, if you just want to Pull Request.

Jono

On 17 November 2015 at 08:20, Jonathan Ferguson jono@spiralarm.com wrote:

It's first mentioned in example five RandomGif.elm.

I think a comment in the code would be enough, possibly including a link
to the appropriate source documentation.

My experience was "I'm unsure what this means, I assume it is a very short
alias or macro."

As an aside, I tried it in the REPL and got the following error:

(=>) a b = (a,b)

ERRORS in repl-temp-000.elm

#################################################

-- SYNTAX PROBLEM --------------------------------------------
repl-temp-000.elm

I ran into something unexpected when parsing your code!

4| =>

 ^

I am looking for one of the following things:

an expression

whitespace

On 16 November 2015 at 23:27, Evan Czaplicki notifications@github.com
wrote:

It expands out to this definition:

(=>) a b =
(a, b)

So when you say "abc" => 123 it is the same as ("abc", 123).

Where did you first see this, and where would you recommend putting a
note about it? I believe it is used in many places. I need to know your
particular experience to add hints in a targeted and helpful way.

โ€”
Reply to this email directly or view it on GitHub
#40 (comment)
.

I suggest removing this altogether from the tutorial. People are trying to understand the Elm architecture in this tutorial and this adds an unnecessary layer of cognitive load.

I need to know your particular experience to add hints in a targeted and helpful way.

Elm Syntax โ€” Applying Functions was the first place where I have expected to get the explanation.

@sporto I'm against removing it, I was confused as hell by that but once I came here and understood it I found it valuable.

If it was introduced like in @jonoabroad's code from noredink I'd see no problem.

How should this be entered into the REPL? I tried:

"abc" => 123 and got,

-- NAMING ERROR ---------------------------------------------- repl-temp-000.elm

Cannot find variable =>

3โ”‚ "abc" => 123
^^^^^^^^^^^^

The operator => is not in the standard library, so it's not in scope in just any repl session.

I haven't been able to find it anywhere in the documentation. I'm thinking it is a detail of one of the libraries that may not be intended for use outside the library. Have I missed something?

What you seem to have missed are some of the comments in the discussion above. For example, this:

It's first mentioned in example five RandomGif.elm.

Which is indeed the case. See

.

I did see that. It's the reason I came to this git issue looking for answers.

It is a mystery sitting there with no comments, it doesn't work in the REPL, and I can't find it in the documentation. I do see how it is used in the view below. Easy enough, but no docs makes me wonder if it is really intended for general use.

I don't get what exactly you mean by "it doesn't work in the repl". Of course, it will work in the repl if you load a file that defines it. Like with any other function. If you write your own program with a function named g, then that function will be available because you defined it. Somebody importing your code will be able to use it as well, others won't. And if you don't document it, it won't be documented; if you do, it will. There's nothing special about (=>) in any of these regards. It's a helper function used in this example. It would be good to explain it, because the purpose of all these examples is exactly explanation. But there's no need to suspect any specialty here, like this operator somehow being a detail of some library that the public shouldn't know about or some such.

so you are saying it can be defined in a file that you load, but can't be defined directly in the REPL?

(=>) = (,)
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm

I ran into something unexpected when parsing your code!

4โ”‚ =>
^
I am looking for one of the following things:

an expression
whitespace

The expanded syntax also does not work:

> (=>) a b = (a,b)
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm

I ran into something unexpected when parsing your code!

4โ”‚   =>
     ^
I am looking for one of the following things:

    an expression
    whitespace

This is indeed mysterious.

Isn't it? By it's self it seems insignificant (=>), but it makes me wonder if there is something bigger that I'm missing, and this is just a symptom of that.

so you are saying it can be defined in a file that you load, but can't be defined directly in the REPL?

I was saying that it can be defined in a file that you load. I didn't comment on whether it can be defined directly in the repl. Because you hadn't asked about that. You had asked about whether it can be used in the repl. And the answer to that is yes, no mystery at all. You asked why

"abc" => 123

didn't work in the repl, and the answer to that is that it cannot work if it hasn't been defined.

Now, the question why it is not possible to define (=>) in the repl while it is possible to define it in a file, is different, and either an issue for https://github.com/elm-lang/elm-compiler or for https://github.com/elm-lang/elm-repl. It doesn't have anything to do with (=>) being a special operator of a special library. It's just an issue of "operator definitions don't work in the repl".

...opening an issue with elm-repl. thanks for the insights!

elm-lang/elm-repl#110

It took me forever to realize what was going on here. I think the rocket operator should be dropped from the architecture tutorial, it's totally confusing without looking directly at the example. Especially for people just learning the language and the concepts.

I don't use it in http://guide.elm-lang.org/ anymore