Lets start with an example:
import MyModule exposing (TypeA,TypeB,TypeC(..))
One of these types is a type with exposed constructor, one is an opaque type and one is an alias type.
As you can see the type with exposed constructor is easy to identify, but the opaque type and the alias type are not.
The problem is now that my alias type has a constructor while my opaque type has not. In a bigger project this can get quite annoying.
Let me show you what i mean:
In a package of mine i exedentally used an alias as an opaque type. Even worse: I could chance the definition of the alias type and it was not considered a major chance.
Here is the commit:
Yeah, I know. The commit is a mess.
The change happend in the module Graphics.Abstract, that is used to hide all my opaque types as well as alias types. I learned my lession, now i only have opaque types in the file. Also note: this is 0.18 code!
module PixelEngine.Graphics.Abstract exposing (..)
type alias ContentElement msg =
{- { elementSource : ElementSource <- this is the old code -}
{ elementType : ElementType
, customAttributes : List (Attribute msg)
, uniqueId : Maybe String
}
There was actually a test file using the ContentElement constructor that broke as a result of this change. And up untill now I should be the only one using this package, so no real code was hurt by this change. But still, i had expacted it to be a major change.
Im not saying that i blame the versioning-system, im just saying that it is very confusing.
So how could we fix this?
we could force alias types to be epxosed with (…). This way at least we know that an element has a useable constructor. Personally i do not like this chance, also because it would not be able to be implemented in 0.19.
i propose to add a new syntax:
import MyModule exposing ((TypeA),TypeB,TypeC(..))
This syntax could be optional. And we could let elm-format help us replace the existing code. When using it, the difference between opaque and alias type would be always clear. This proposal would not break any existing code and could be implemented in 0.19.
If you have another idea how one could make that difference clearer, please, now is your chance.