diff --git a/README.md b/README.md index ed25b6067..b033324ff 100644 --- a/README.md +++ b/README.md @@ -58,22 +58,64 @@ designed to support source code queries, allowing for powerful IDE integrations such as code completion and refactoring tools. -## Examples +## Example + + +
+fn fibonacci(n: i32) -> i32 {
+    if n <= 1 {
+        n
+    } else {
+        fibonacci(n - 1) + fibonacci(n - 2)
+    }
+}
 
-```mun
-fn main() {
-    // Comments: Mun natively supports bool, f32, f64, i8, u8, i16, etc.
+// Comments: functions marked as `pub` can be called outside the module
+pub fn main() {
+    // Native support for bool, f32, f64, i8, u8, u128, i128, usize, isize, etc
     let is_true = true;
     let var = 0.5;
 
-    let sum = add(30, 40);
+    // Type annotations are not required when a variable's type can be deduced
+    let n = 3;
+
+    let result = fibonacci(n);
+
+    // Adding a suffix to a literal restricts its type
+    let lit = 15u128;
+
+    let foo = record();
+    let bar = tuple();
+    let baz = on_heap();
+}
+
+// Both record structs and tuple structs are supported
+struct Record {
+    n: i32,
 }
 
+// Struct definitions include whether they are allocated by a garbage collector
+// (`gc`) and passed by reference, or passed by `value`. By default, a struct
+// is garbage collected.
+struct(value) Tuple(f32, f32);
+
+struct(gc) GC(i32);
+
 // The order of function definitions doesn't matter
-fn add(a: i64, b: i64) -> i64 {
-    a + b
+fn record() -> Record {
+    // Mun allows implicit returns
+    Record { n: 7 }
 }
-```
+
+fn tuple() -> Tuple {
+    // Mun allows explicit returns
+    return Tuple(3.14, -6.28);
+}
+
+fn on_heap() -> GC {
+    GC(0)
+}
+
## Documentation