# SSCCE for the entire Elm syntax

**URL:** https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691
**Category:** Request Feedback
**Created:** [May 2, 2020, 10:49am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691 "2020-05-02T10:49:04Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 2, 2020, 10:49am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/1 "2020-05-02T10:49:05Z")

</div>

For some reason, I was curious to see how a [Short, Self Contained, Correct Example](http://sscce.org/) of the **entire** Elm syntax would look like.

I started with the counter example and added things as they came to my mind making sure to `elm-format` after each change. [This is the result.](https://ellie-app.com/8L4N579KBM5a1)

Did I missed any piece of syntax?

What would you add? What would you take away? What would be your take on a minimal example of the entire syntax?

How would you change the comments so that is easier to understand. (I tried to keep the comments to a minimum).

---

<div class="post-metadata">

### Author: ![Philipp\_Krueger](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/philipp_krueger/32/2674_2.png) [@Philipp\_Krueger](https://discourse.elm-lang.org/u/Philipp_Krueger)
#### Post date: [May 2, 2020, 11:57am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/2 "2020-05-02T11:57:30Z")

</div>

Nice! Seems useful to me. What about record extension?

What is your goal for this, btw?

---

<div class="post-metadata">

### Author: ![lydell](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lydell/32/178_2.png) [@lydell](https://discourse.elm-lang.org/u/lydell)
#### Post date: [May 2, 2020, 12:00pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/3 "2020-05-02T12:00:21Z")

</div>

Cool!

- Should there be an example of destructuring in `let in`? `let (Foo foo) = bar`
- Should there be a toplevel definition without a type annotation?
- And a `let in` _with_ a type definition? Maybe also one where a “type variable is re-used from the parent function type annotation” (I think that’s a thing).
- Maybe a multi-line type annotation?
- Is there any formatting we want to add, that elm-format does not output? Such as single-line if.

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 2, 2020, 3:14pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/4 "2020-05-02T15:14:01Z")

</div>

> [@Philipp\_Krueger](#):
>
> What about record extension?

Good Point. Maybe a phantom type too.

> [@Philipp\_Krueger](#):
>
> What is your goal for this, btw?

It’s just playing. No serious goals here. I sometime get questions in my mind that I would like answered. I guess I do am interested in how low can one go. Can all these things be expressed in less code? 🙂

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 2, 2020, 3:36pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/5 "2020-05-02T15:36:47Z")

</div>

I have produced a [new version](https://ellie-app.com/8L8w7RH656na1) integrating the suggestions that were easier to think through.

> - Is there any formatting we want to add, that elm-format does not output? Such as single-line if.

I love the uniformity of `elm-format` and I would like the example to stay formatted. But you have a good point here. I know that Evan publishes code that has unconventional formatting ( [like this section](https://github.com/elm/package.elm-lang.org/blob/master/src/frontend/Main.elm#L139-L158) ) and single line ifs that fit into the line width limit are one of the things I wish `elm-format` would allow.

---

<div class="post-metadata">

### Author: ![gampleman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/gampleman/32/43_2.png) [@gampleman](https://discourse.elm-lang.org/u/gampleman)
#### Post date: [May 3, 2020, 6:17pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/6 "2020-05-03T18:17:11Z")

</div>

There are some weirder bits of Elm syntax:

- WebGL literals (technically this could inflate the example considerably since Elm subsumes most, but not all GLSL syntax).
- The syntax used internally like effect managers / kernel code (not sure there would be much value in this)
- There are various phantom type/extensible record tricks. Some of these were first popularised by elm-css.

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 4, 2020, 4:29am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/7 "2020-05-04T04:29:50Z")

</div>

> [@gampleman](#):
>
> The syntax used internally like effect managers / kernel code (not sure there would be much value in this)

I would rather stay away from the private API of the runtime as this is not available for regular users.

---

<div class="post-metadata">

### Author: ![drathier](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/drathier/32/915_2.png) [@drathier](https://discourse.elm-lang.org/u/drathier)
#### Post date: [May 4, 2020, 8:32am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/8 "2020-05-04T08:32:32Z")

</div>

Cool! Wish this existed years ago already! This is the relevant AST if you want to make sure you’ve covered everything: [https://github.com/elm/compiler/blob/master/compiler/src/AST/Canonical.hs](https://github.com/elm/compiler/blob/master/compiler/src/AST/Canonical.hs)

---

<div class="post-metadata">

### Author: ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)
#### Post date: [May 4, 2020, 9:01am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/9 "2020-05-04T09:01:21Z")

</div>

This will be great for stress-testing `elm-in-elm`, thanks @pdamoc!

---

<div class="post-metadata">

### Author: ![stoft](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/stoft/32/753_2.png) [@stoft](https://discourse.elm-lang.org/u/stoft)
#### Post date: [May 4, 2020, 2:01pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/10 "2020-05-04T14:01:26Z")

</div>

Should `<<` be there as well?

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 5, 2020, 6:41am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/11 "2020-05-05T06:41:00Z")

</div>

I have extended [the example](https://ellie-app.com/8MkkjZfsgWKa1) to cover extensible records, phantom types and the WebGL shaders language.

For phantom types and the shader language I just left the code as dead code.

I have also moved the code into [a github repository](https://github.com/pdamoc/elm-syntax-sscce).

---

<div class="post-metadata">

### Author: ![dmy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dmy/32/702_2.png) [@dmy](https://discourse.elm-lang.org/u/dmy)
#### Post date: [May 5, 2020, 7:30am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/12 "2020-05-05T07:30:32Z")

</div>

I like the idea.

From a quick glance, it seems that at least the following are missing:

- multiline strings (with `"""`)
- tuples and unit type pattern matching
- `exposing (..)` import
- characters (`Char` with `'`)
- records fields accessors without the syntax suggar (`.field record`)

You could also show that record fields accessors work on expressions, for example:

```auto
(named "myname").name

```

Also have a look there:

> [@Lesser known syntax](https://discourse.elm-lang.org/t/lesser-known-syntax/641):
>
> Please share your knowledge of any lesser known Elm syntax that is not mentioned in the official overview ([http://elm-lang.org/docs/syntax](http://elm-lang.org/docs/syntax)) and is possibly buried somewhere else and easy to miss. I was pleased to find out that for function parameters that are records or tuples, you do not need to choose between either destructuring that parameter OR giving a name to it as a whole. You can do both at the same time using the wrapping (… as foo) syntax! f a b c = … f a {x, y} c = … …

There are other things like multiple imports using the same alias.

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 5, 2020, 8:04am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/13 "2020-05-05T08:04:18Z")

</div>

I have [updated the example](https://ellie-app.com/8Mmqh7pGPxta1) to cover the things you pointed at.

I just added dead code to exemplify some of the things.

LATER EDIT: I also added an example for `Debug.log` usage and for multiple declarations for `_`.

---

<div class="post-metadata">

### Author: ![ianmackenzie](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/ianmackenzie/32/86_2.png) [@ianmackenzie](https://discourse.elm-lang.org/u/ianmackenzie)
#### Post date: [May 5, 2020, 10:13pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/14 "2020-05-05T22:13:05Z")

</div>

Seems like a cool resource to point people to if they want to get a pretty thorough overview of Elm syntax! A couple potential additions:

- An example of partial function application
- An example of using an operator as a function, either in prefix form like

```auto
three =
    (+) 1 2

```

or perhaps as an argument to a higher-order function, e.g.

```auto
sums =
    List.map2 (+) [1, 2, 3] [10, 20, 30]

```

---

<div class="post-metadata">

### Author: ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)
#### Post date: [May 6, 2020, 5:08am UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/15 "2020-05-06T05:08:18Z")

</div>

I have [updated the example](https://ellie-app.com/8MKgxxwxSW2a1) with your suggestions.

It is very funny how I missed partial application as this is something I do all the time. Using infix operators in higher order functions is less frequent in my code but still… I use it from time to time. The use-case for infix operator as prefix function that I have in my code is actually partial application of the operator.

---

<div class="post-metadata">

### Author: ![antew](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/antew/32/2102_2.png) [@antew](https://discourse.elm-lang.org/u/antew)
#### Post date: [May 6, 2020, 2:05pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/16 "2020-05-06T14:05:35Z")

</div>

This is great! I’ve seen a lot of people new to Elm ask for this sort of document, thank you for making it.

---

<div class="post-metadata">

### Author: ![razze](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/razze/32/1650_2.png) [@razze](https://discourse.elm-lang.org/u/razze)
#### Post date: [May 7, 2020, 12:30pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/17 "2020-05-07T12:30:19Z")

</div>

keep in mind that you’ll be missing glsl and the internal apis like `infix`

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [May 17, 2020, 12:30pm UTC](https://discourse.elm-lang.org/t/sscce-for-the-entire-elm-syntax/5691/18 "2020-05-17T12:30:20Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
