# Is it possible to create the following Type

**URL:** <https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545>\
**Category:** Learn\
**Created:** [October 24, 2019, 4:00pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545 "2019-10-24T16:00:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hari\_Roshan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hari_roshan/32/2588_2.png) [@Hari\_Roshan](https://discourse.elm-lang.org/u/Hari_Roshan)\
**Post date:** [October 24, 2019, 4:00pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/1 "2019-10-24T16:00:47Z")

</div>

Can we do the following in elm?

```
type Overlay = MovingAverage | Volume
type Standalone = RSI | MACD
type Indicator = Overlay | Standalone

```

If i do this I can’t create Indicator type. but if I do the following

```
type Indicator = A Overlay | B Standalone

```

then I can create Indicator type using

```
A MovingAverage

```

Is it possible to create a type without extra data constructors

---

<div class="post-metadata">

**Author:** ![jfmengels](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jfmengels/32/3124_2.png) [@jfmengels](https://discourse.elm-lang.org/u/jfmengels)\
**Post date:** [October 24, 2019, 4:06pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/2 "2019-10-24T16:06:02Z")

</div>

Hi @Hari_Roshan,

As you said, `type Indicator = Overlay | Standalone` is not possible.

The way you proposed is how we usually do things (albeit with more comprehensive names than A and B)

```elm
type Indicator
    = OverLayIndicator OverLay
    | StandaloneIndicator Standalone

```

---

<div class="post-metadata">

**Author:** ![Hari\_Roshan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hari_roshan/32/2588_2.png) [@Hari\_Roshan](https://discourse.elm-lang.org/u/Hari_Roshan)\
**Post date:** [October 24, 2019, 4:07pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/3 "2019-10-24T16:07:44Z")

</div>

Thank you for your quick reply. 😌

---

<div class="post-metadata">

**Author:** ![Hari\_Roshan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hari_roshan/32/2588_2.png) [@Hari\_Roshan](https://discourse.elm-lang.org/u/Hari_Roshan)\
**Post date:** [October 24, 2019, 7:33pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/4 "2019-10-24T19:33:50Z")

</div>

I ran into another problem. I made the following type. But when i add the type to Msg of update it gives following error.

```
type Overlay
    = MovingAverage Int (Array Float)
    | BollingerBand

type Standalone
  = RSI
  | MACD

type Indicator
    = OverlayIndicator Overlay
    | StandaloneIndicator Standalone
type Msg =
    AddIndicator Indicator -- when i add this. it gives the following error

```

```auto
./src/elm/Main.elmError: Compiler process exited with error Compilation failedSuccess! Compiled 2 modules.
elm.exe: Map.!: given key is not an element in the mapCallStack (from HasCallStack): error, called at libraries\containers\Data\Map\Internal.hs:603:17 in containers-0.5.10.2:Data.Map.Internal

```

---

<div class="post-metadata">

**Author:** ![jfmengels](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jfmengels/32/3124_2.png) [@jfmengels](https://discourse.elm-lang.org/u/jfmengels)\
**Post date:** [October 24, 2019, 8:00pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/5 "2019-10-24T20:00:07Z")

</div>

i’m not sure what the source of the problem is, but the “Map.!” error happens with Elm 0.19.0 when you compile using `--debug`.  
I suggest upgrading to the newly released 0.19.1 which solves the problem, or stop using `--debug`.

---

<div class="post-metadata">

**Author:** ![Hari\_Roshan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/hari_roshan/32/2588_2.png) [@Hari\_Roshan](https://discourse.elm-lang.org/u/Hari_Roshan)\
**Post date:** [October 24, 2019, 8:57pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/6 "2019-10-24T20:57:15Z")

</div>

Thanks a lot. It did solved the issue. 😌

---

<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:** [November 3, 2019, 8:57pm UTC](https://discourse.elm-lang.org/t/is-it-possible-to-create-the-following-type/4545/7 "2019-11-03T20:57:21Z")

</div>

Closed on November 3, 2019, 8:57pm UTC

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