elm-format and long strings

55 views
Skip to first unread message

Duane Johnson

unread,
Sep 25, 2016, 5:14:52 PM9/25/16
to elm-d...@googlegroups.com
I'm curious if there are other options for making long inline strings look good in Elm:

1. Use double quotes and (++) to concatenate. Cons: adds runtime operation; must add parens around the string block if it's an argument, e.g. the following does not compile

```elm
        |> Dict.insert 2
            (Story
                "John Oliver"
                "Far, far away in a land called teevee, there " ++
                "lived a wise man whose laugh you could see."
            )
```

To compile, it must become:

```elm
        |> Dict.insert 2
            (Story
                "John Oliver"
                ("Far, far away in a land called teevee, there "
                    ++ "lived a wise man whose laugh you could see."
                )
            )
```

2. Use triple-double quotes. Cons: includes whitespace, and in combination with elm-format, whitespace is not within control:

```elm
        |> Dict.insert 2
            (Story
                "John Oliver"
                """Far, far away in a land called teevee, there
                lived a wise man whose laugh you could see."""
            )
```

The second string becomes "Far, far away in a land called teevee, there                lived a wise man whose laugh you could see." (Note extra spaces between "there" and "lived").

3. Put strings on one big line. Cons: not pretty, hard to see in a text editor without line wrapping.

Any suggestions?

Thanks,
Duane

OvermindDL1

unread,
Sep 25, 2016, 5:23:22 PM9/25/16
to Elm Discuss
I personally put long strings in their own global variable/function while spaced as they should with ++ (the compiler certainly should optimize 'that'), so the above would be for me:
```elm
story_johnOliver_desc =
  "Far, far away in a land called teevee, there " ++
  "lived a wise man whose laugh you could see."

# elsewhere
        |> Dict.insert 2
            (Story
                "John Oliver"
                story_johnOliver_desc
            )
```

Though to be honest I only use `++` on quite long strings, the above form I'd still do as a single line, but still in its own call.
Reply all
Reply to author
Forward
0 new messages