On Tuesday, March 7, 2017 at 4:28:52 AM UTC, Matthieu Pizenberg wrote: > > Hi everyone, > > I would like to have the point of view of the community regarding some > private/public types code organisation. I have some types very useful to > many sub modules that are currently publicly exposed in a Types module. In > order to hide the type implementation, I wonder what you think of a module > organization like below: > > -- Private/Types.elm > module Private.Types exposing (Point2d(Point2d)) > type Point2d = Point2d (Float, Float) > > -- Public/Types.elm > module Public.Types exposing (Point2d) > import Private.Types exposing (Point2d) > > -- Point2d.elm > module Point2d exposing (fromCoordinates) > import Private.Types exposing (..) > fromCoordinates : (Float, Float) -> Point2d > > The Public.Types would act as a "symbolic" link to the equivalent private > types without exposing the type constructors. However I wonder if it means > that fromCoordinates is returning a non exposed private Point2d type or if > the linkage to the equivalent public type is effective. Is this considered > bad practice, and/or potentially forbidden in future version of elm? >
There are libraries which expose 'private' types, just like you describe. 'mdgriffith/elm-style-animation' is an example: http://package.elm-lang.org/packages/mdgriffith/elm-style-animation/3.5.5/Animation Exposes: type alias State = Animation Never But, Animation is defined in a module that is not exposed as part of the package: https://github.com/mdgriffith/elm-style-animation/blob/3.5.5/src/Animation/Model.elm However, as the constructor for Animation is exposed by its module, I am not prevented from deconstructing it or pattern matching against it. I think the rule is that "exposed-module" in a package definition provides a public window onto a package. Anything visible through that window is public, even if its definition is not in one of the named exposed-modules. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
