module Size exposing (Size, Maybe, ..etc..)
type Size = ...
type Maybe = Valid Size | Negative
----------------
module Main ..etc..
import Size exposing (Size)
case ... of
Size.Negative -> ...
Size.Valid measurement -> ...
Since this example doesn’t expose the constructors, we get “never heard of variant Negative”.
import Size exposing (Size,Maybe(..))
This exposes the constructors, and the above code works, but then elsewhere in the Main module:
type MaybeMessage = Maybe String
error: The `Maybe` type needs 0 arguments, but I see 1 instead
Which means it assumes I’m talking about Size.Maybe. But I basically always explicitly name the module for anything exposed in it to keep my namespaces clean. So if I want Size.Maybe I’ll call it that, if I want Size.Negative constructor I’ll call that that as well.
Is it possible to expose import those constructors without dumping the Size.Maybe type into global namespace?
import Size exposing (Size,Maybe(..) as Size.Maybe)
Separately, I think using the name Maybe for your module might be misleading to anyone who comes to read your code, including you, a year from now since it’s a core type. Instead of marking it as Valid, something like
parse : ? -> Result Error Size
parse input =
-- parse to either a Size or an error
Not certain this fits with your code but generally I recommend trying to parse a value instead of separately mark something as valid/invalid. If you need to keep some type denoting whether or not it’s valid, then I’d go with something like