elm-lang.org icon indicating copy to clipboard operation
elm-lang.org copied to clipboard

Exporting Union Types in Elm Syntax

Open trotha01 opened this issue 9 years ago • 9 comments

If we have a submodule with: type Animal = Cat | Dog

we can export Cat and Dog with: module Submodule (Animal(..)) where

and import with import Submodule exposing (Animal(..))

Can we add something that explains this on the syntax page

trotha01 avatar Feb 06 '16 21:02 trotha01

It is mentioned here Elm Syntax — Modules already, but I agree, it is not explicit. The best I could think of is adding a commentary about the presence of open imports for Union Types in Modules section.

halfzebra avatar Apr 07 '16 17:04 halfzebra

I think it should be mentioned here too: https://guide.elm-lang.org/types/union_types.html

francescortiz avatar Sep 28 '16 21:09 francescortiz

Yeah, this is mysterious to a beginner and not emphasized enough in the docs (or at least not enough that I remembered it). This github issue saved me :-)

granmoe avatar Mar 19 '17 00:03 granmoe

Glad I found this github issue, because I couldn't deduct this from Elm Syntax - Modules

daniel-kun avatar May 10 '17 17:05 daniel-kun

Puh I am so happy to have seen this issue... Now all my Types go into a single Types.elm

zmijunkie avatar Sep 20 '17 19:09 zmijunkie

This was a good 30 minutes of headache for me... glad this issue is the first result when you google it.

ian-moore avatar Oct 05 '17 03:10 ian-moore

For anyone looking here. Export your union type with module Module exposing (UnionType(..), otherthing, etc) and import it with import Module exposing (UnionType(..)).

fiatjaf avatar Oct 07 '17 22:10 fiatjaf

For anyone looking here. Export your union type with module Module exposing (UnionType(..), otherthing, etc) and import it with import Module exposing (UnionType(..)).

I somehow knew that importing it with (..) was possible, but I didnt think of exporting for some reason. ¯_(ツ)_/¯

downloadpizza avatar Aug 29 '19 13:08 downloadpizza

This means that you can't access Dog and Cat without explicitly exposing them right? Just import Submodule isn't enough to access them it seems like.

tankorsmash avatar Jul 30 '21 01:07 tankorsmash