# What exactly is the 'Program' in elm programs?

**URL:** <https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748>\
**Category:** Learn\
**Created:** [May 8, 2020, 4:29pm UTC](https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748 "2020-05-08T16:29:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![54166viper](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/54166viper/32/3268_2.png) [@54166viper](https://discourse.elm-lang.org/u/54166viper)\
**Post date:** [May 8, 2020, 4:29pm UTC](https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748/1 "2020-05-08T16:29:25Z")

</div>

I’m new to elm and I’m currently trying to read the official examples.  
When I came across `Browser.sandbox`, the elmtooling in vscode told me its definition:

```
sandbox :
{ init : model
, view : model -> Html msg 
, update : msg -> model -> model
}
-> Program () model msg

```

I guess the image of sandbox is a partial function of Program, where two slots have already been filled, requiring only one argument to be given (which I suppose is the ‘flag’)  
Then I wondered what the ‘Program’ means. I was then told by the editor that ‘Program’ describes an elm program (sounds fairly reasonable). What really made me confused is the following line:

```
type Program flag model msg = Program

```

Can someone help me understand this line? How can this line be parsed?

---

<div class="post-metadata">

**Author:** ![malaire](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@malaire](https://discourse.elm-lang.org/u/malaire)\
**Post date:** [May 8, 2020, 4:41pm UTC](https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748/2 "2020-05-08T16:41:31Z")

</div>

Hello and welcome to Elm. 🙂

I’m not good at explaining the `sandbox`, but as for `Program`: Definitions like this in `core` packages generally mean that the type is implemented internally by the compiler and there is no definition for it in Elm syntax.

Parsed literally

```
type SomeType = SomeType

```

means that `SomeType` is a unit type with only a single possible value: `SomeType`

Adding some type parameters to type definition like with `Program`

```
type OtherType a b c = OtherType

```

still means that it’s a unit type.

While there are uses for unit types, it doesn’t make any sense for `Program` to be one, and it isn’t. It’s just a custom to define internally implemented types like `Program` as unit types.

---

<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 8, 2020, 5:32pm UTC](https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748/3 "2020-05-08T17:32:58Z")

</div>

> [@54166viper](#):
>
> Can someone help me understand this line? How can this line be parsed?

What you see here is a phantom type, a type whose type parameters do not appear on the right side of the definition. This is useful when you want to ensure type safety.

The actual implementation of a `Program` is a black box. It is implemented by the runtime in JS.

Elm has a private API (available only for core packages) that allows the implementation of things in JS that are trusted by the compiler. So, if the `sandbox` private implementation says that it has a type of `Program () model msg` the compiler trusts it without needing to go check the implementation.

You will find this pattern of using phantom types for types that are implemented in JS. `Cmd`, `Sub` and `Task`, are also implemented as phantom unit types. 😉

---

<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 18, 2020, 5:33pm UTC](https://discourse.elm-lang.org/t/what-exactly-is-the-program-in-elm-programs/5748/4 "2020-05-18T17:33:02Z")

</div>

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