Modules in Marigold represent datatypes. They act like the functional version of an object-oriented class.
module keywordModules are defined by using the module keyword.
Modules may contain
Items in modules are accessed like: [module name].[module item name]
Cons functionCons (short for constructor) is used to initialize “objects” in Marigold. It can be called
both with [module name].Cons or simply with [module name].
Sometimes, you don’t want to say the module name everytime you access a module item. In this case,
you can use the unpack keyword
In Marigold, you may import modules from other files. To do so, you must name the file identically to the name
of the modules. So, if you want to import an Employee module, it must be in employee.mg.
Modules may be in different folders than the script you are importing it into. In this case, put the name of the directory at the start, followed by a .
For example if you have a project with a myproject/main.mg file and a myproject/modules/employee.mg file, to access
the Employee module from main.mg, at the top of your file put import Modules.Employee;.
The Packages directory has an alias ($), meaning if you’d like to access myproject/packages/employee.mg, simply
type import $Employee;.
The problem with the current setup is that sufficiently large scripts will begin with a wall of imports followed
by a wall of unpacks, to use the imported modules. To import a module, and then to unpack it, use the importall
keyword.
importall Employee;
achieves the same result as
import Employee; unpack Employee;