diff --git a/spec.md b/spec.md index 2f8a7ff..d07af05 100644 --- a/spec.md +++ b/spec.md @@ -213,4 +213,56 @@ However, infinite types without size *are* allowed: This is *not* allowed: ``` &a a -``` \ No newline at end of file +``` + +## module system +Each file is a "compilation unit" + +When compiling a compilation unit, the following inputs have to be provided: +- any amount of files containing signatures of exported definitions. + only definitions of the compilation unit that are in one of the signature files will get exported. +- any amount of other files containing imported definitions + +Note that there is no practical difference between signature and source files. + +### Example +Export signature file `List.li`: +``` +type List[t] = 'End | 'Cons {head:t, tail:List[t]} + +# not providing a function body makes it a function signature definition +def [t] `a++b`(a: List[t], b: List[t]) -> List[t]; + +def [t] Match.`a++b`( + value: List[t], + l: List[t], + r: MatchUtil.Var[List[t]] +) -> Option[{ r: List[t] }]; +``` + +Import signature file `Option.li`: +``` +type Option[t] = 'None | 'Some t; +``` + +Compilation unit `List.lu`: +``` +def [t] `a++b`(a: List[t], b: List[t]) -> List[t] { + # ... +} + +def [t] Match.`a++b`( + value: List[t], + l: List[t], + r: MatchUtil.Var[List[t]] +) -> Option[{ r: List[t] }] { + # ... +} +``` + +### Notes +Each compilation unit gets compiled to implementation-specific bytecode. + +Templated functions can only be compiled partially during a compilation unit. This will impact compile speeds. + +Avoid templated functions wherever possible. \ No newline at end of file