Modules are way how to group Elm functions in meaningful groups. This post is part of the functional language series.
In Elm, the module is starting block. Elm is a functional programming language, which means that everything happens in functions. Elm creators decided that Elm’s function must have a module.
Let's create a string from number 46 using the Debug module that comes with Elm.
Have you helped yourself with a great
TAB feature in
repl? No, because
elm repl does not support it. But history works, you can use up and down arrows for history feature. Time to use your favorite editor and create an Elm module.
You need to initialize your first elm project:
For now, you just need to know that it creates
src the folder where you should put your elm source files. Create a file with the name
src/Vat.elm. Elm requires that the module name and file name are the same.
Congratulations, you created your first elm module. You learned the following keywords:
modulethis is how you start the module definition.
Vatis the module name.
Remember that the module name should be the same as the module file name. Start module name with uppercase. The module name should give a reader a hint about what this module do.
exposinga list of functions and variables that are available to the world.
Remember, do not use exposing on module definition but on the module
import. This will make your code more readable.
- We declared a variable
crothat represents the Croatian Vat tax value.
elmis Elm file extension
Vat in repl:
elm make src/Vat.elm
elm make compiles Vat.elm so it could be run:
elm Float a datatype.
- how to initialize the project
- how to create a module
- module name naming convention
- how to compile a module
- how to use it in