elm-community / elm-faq

FAQ about the Elm language.
https://faq.elm-community.org/
22 stars 24 forks source link

The => operator is no longer part of the language #40

Closed maxf closed 7 years ago

maxf commented 7 years ago

I can't find the commit where it's been removed but ["color" => "red"] triggers an error, as of 0.18

fredcy commented 7 years ago

The => operator never was part of the language or core packages as far as I know. But it was a common idiom for apps to define

(=>) = (,)

and then use it as described in the FAQ. So unless that common usage has disappeared I think we should leave this FAQ item in place.

Thoughts, anyone?

maxf commented 7 years ago

I see. Makes sense. How do you define (=>) = (,) ?

fredcy commented 7 years ago

Literally what you typed is what does it: (=>) = (,)

The type of (,) is a -> b -> (a, b). That is, it takes two arguments and constructs a tuple value from them

The expression might look strange because the way to refer to an operator as a function value is to surround it by parens as above. Also, the tuple-forming operator (,) is unusual because it has variations like (,,) for producing tuples of different arities (3 in that case).

maxf commented 7 years ago

Maybe I missed something but (=>) = (,) doesn't do it for me.

foo = (,) works and lets you write foo 1 2 (but not (1 foo 2)) but (=>) = (,) yields a syntax error.

fredcy commented 7 years ago

Perhaps you are trying it in elm-repl? It won't work there. It will work in code compiled with elm-make or at http://elm-lang.org/try.

maxf commented 7 years ago

You're right it works. I thought I'd tried. Anyway, this question should remain only if => is found a lot in existing code. I don't know if it's the case.

fredcy commented 7 years ago

I think the existing description of => is fairly clear about it being an idiom and not part of the language. As such I'm inclined to leave the text as is.

Thanks for taking the time to contribute.