hello_mod
A multi-module project: one directory, three modules, no manifest.
examples/projects/hello_mod/src/main.dawn
# A multi-module project: one directory, three modules, no manifest.
#
# `src/` is the module root, so a file at `src/greet/words.dawn` is the module
# `greet/words` and nothing has to be registered anywhere. A project needs a
# dawn.toml only once it has dependencies -- see the json example next door.
#
# Run: dawn run examples/projects/hello_mod
use greet/words.{Lang, English, Chinese, greeting, EXCLAIM}
use util/nums
fn line(lang: Lang) -> String = greeting(lang) ++ EXCLAIM
pub fn main() -> Unit !io = {
println(line(English))
println(line(Chinese))
println(to_string(nums.doubled(21)))
match nums.first([7, 8, 9]) {
Some(n) -> println(to_string(n))
None -> println("empty")
}
println(to_string(English))
}
examples/projects/hello_mod/src/greet/words.dawn
pub type Lang =
| English
| Chinese
derive Show
pub const EXCLAIM: String = "!"
pub fn greeting(lang: Lang) -> String =
match lang {
English -> "Hello"
Chinese -> "你好"
}
test "greeting picks the language" {
assert greeting(English) == "Hello"
assert greeting(Chinese) == "你好"
}
examples/projects/hello_mod/src/util/nums.dawn
pub fn doubled(x: Int) -> Int = x * 2
pub fn first[T](xs: List[T]) -> Option[T] = get(xs, 0)