Is it possible to create the following Type

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

1 Like

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)

type Indicator
    = OverLayIndicator OverLay
    | StandaloneIndicator Standalone

Thank you for your quick reply. :relaxed:

1 Like

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
./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-

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.

Thanks a lot. It did solved the issue. :relaxed:

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