@@ -3,6 +3,8 @@
33When getting started with Elm, it is pretty common to have questions about how the `import` declarations work exactly. These questions usually arise when you start playing with the `Html` library so we will focus on that.
44
55
6+<br>
7+
68## `import`
79
810An Elm file is called a **module**. To access code in other files, you need to `import` it!
@@ -36,6 +38,8 @@ We are referring to the [`Html`](http://package.elm-lang.org/packages/elm-lang/h
3638> **Note:** Modules do not contain other modules. So the `Html` module *does not* contain the `Html.Attributes` module. Those are separate names that happen to have some overlap. So if you say `import Html` you *do not* get access to `Html.Attributes.style`. You must `import Html.Attributes` module separately.
3739
3840
41+<br>
42+
3943## `as`
4044
4145It is best practice to always use *qualified* names, but sometimes module names are so long that it becomes unweildy. This is common for the `Html.Attributes` module. We can use the `as` keyword to help with this:
@@ -51,6 +55,8 @@ main =
5155Saying `import Html.Attributes as A` lets us refer to any value or type in `Html.Attributes` as long as it is qualified with an `A`. So now we can refer to [`style`](http://package.elm-lang.org/packages/elm-lang/html/latest/Html-Attributes#style) as `A.style`.
5256
5357
58+<br>
59+
5460## `exposing`
5561
5662In quick drafts, maybe you want to use *unqualified* names. You can do that with the `exposing` keyword like this:
@@ -71,6 +77,8 @@ Saying `import Html exposing (..)` means I can refer to any value or type from t
7177Saying `import Html.Attributes exposing (style)` is a bit more reasonable. It means I can refer to the `style` function without qualification, but that is it. You are still importing the `Html.Attributes` module like normal though, so you would say `Html.Attributes.class` or `Html.Attributes.id` to refer to other values and types from that module.
7278
7379
80+<br>
81+
7482## `as` and `exposing`
7583
7684There is one last way to import a module. You can combine `as` and `exposing` to try to get a nice balance of qualified names:
@@ -87,6 +95,8 @@ main =
8795Notice that I refer to `A.class` which is qualified and `style` which is unqualified.
8896
8997
98+<br>
99+
90100## Default Imports
91101
92102We just learned all the variations of the `import` syntax in Elm. You will use some version of that syntay to `import` any module you ever write.
@@ -112,4 +122,4 @@ You can think of these imports being at the top of any module you write.
112122
113123One could argue that `Maybe` fundamental to how we handle errors in Elm code that it is *basically* part of the language. One could also argue that it is extraordinarily annoying to have to import `Maybe` once you get past your first couple weeks with Elm. Either way, we know that default imports are not ideal in some sense, so we have tried to keep the default imports as minimal as possible.
114124
115−> **Note:** Elm performs dead code elimination, so if you do not use something from a module, it is not included in the generated code. So if you `import` a module with hundreds of functions, you do not need to worry about the size of your assets. You will only get what you use!
125+> **Note:** Elm performs dead code elimination, so if you do not use something from a module, it is not included in the generated code. So if you `import` a module with hundreds of functions, you do not need to worry about the size of your assets. You will only get what you use!