Skip to content
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

Unclear docs about Lists, "(x :: xs)" #1049

Closed
henrik opened this issue Oct 11, 2019 · 3 comments
Closed

Unclear docs about Lists, "(x :: xs)" #1049

henrik opened this issue Oct 11, 2019 · 3 comments

Comments

@henrik
Copy link

henrik commented Oct 11, 2019

Hi!

Noticed that

**Note:** It is usually preferable to use a `case` to test this so you do not
and some other places in the List docs are unclear to me and a co-worker.

Note: It is usually preferable to use a case to test this so you do not forget to handle the (x :: xs) case as well!

We understand that x :: xs has to do with seeing a list as head and tail, but don't get how that applies in this case.

@miniBill
Copy link

miniBill commented Nov 7, 2019

The docs are suggesting that you are probably better off writing

case list of
    [] -> ...
    (x::xs) -> ...

instead of

if List.isEmpty list then
    ...
else
    ....

@henrik
Copy link
Author

henrik commented Nov 7, 2019

Ah! So with x::xs as a way of matching a non-empty list. Think I get it, then. If I can think of a way to clarify this in the docs I’ll make a PR. Thank you!

@henrik henrik closed this as completed Nov 7, 2019
@henrik
Copy link
Author

henrik commented Nov 8, 2019

I'll still try to make that PR, but before that, I thought I'd check something:

Is the naming x :: xs a convention in Elm – if my PR changed those docs (and maybe the code as well?) to say head :: tail, how would that be received? To me, that'd be clearer and likely easier to Google if needed.

henrik added a commit to henrik/core that referenced this issue Nov 17, 2019
As discussed in elm#1049. 

Changing "x :: xs" to "head :: tail" throughout this file might make things een clearer, but I'm not sure if "x :: xs" is an established convention that we want to stick to.
henrik added a commit to henrik/core that referenced this issue Nov 17, 2019
As discussed in elm#1049.

Changing "x :: xs" to "head :: tail" throughout this file might make things even clearer, but I'm not sure if "x :: xs" is an established convention that we want to stick to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants