Reputation: 3294
Given
--module 1
module Module1 exposing (Message) where
type Message
= Test String
| Error Int
--module 2
module Module2 exposing (sayTest, sayError) where
import Module1 exposing (Message)
sayTest : String -> Message
sayTest msg =
Test msg --error
sayError : Int -> Message
sayError code =
Error code --error
processMessage : Message -> String
processMessage msg ->
case msg of
Test s -> s
Error i -> toString i
How do I access Test
and Error
from module 2?
At the moment, I have to create functions in module 1 which when called will create the instances needed but as the list is getting longer, this is becoming impractical.
Upvotes: 6
Views: 1139
Reputation: 36385
You can expose all type constructors for an exported type like this:
module Module1 (Message (..)) where
Alternatively, if you wanted to export only a few type constructors, you can call them out individually:
module Module1 (Message (Test, Error)) where
type Message
= Test String
| Error Int
| Foo String
| Bar
In the above code, the Foo and Bar constructors remain private to the module.
Upvotes: 9