From c68d1af33f6530218de053f5ae4d7fb3c225b5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilma=20Krutr=C3=B6k?= <wilkru-7@student.ltu.se> Date: Tue, 10 Nov 2020 18:32:52 +0000 Subject: [PATCH] Update HOME_EXAM.md --- HOME_EXAM.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/HOME_EXAM.md b/HOME_EXAM.md index 170ab95..f5809c0 100644 --- a/HOME_EXAM.md +++ b/HOME_EXAM.md @@ -443,10 +443,16 @@ Let statements works in a similiar way. ##### Functioncall ```math -\frac{}{}; +\frac{(<e_1,σ> → n_1 ... <e_i,σ> → n_i) → σ(arg1 := n_1, ..., argi := n_i))}{<c,σ> → (x,σ')}; \text{where x is the return value} ``` ```rust + fn a(x: i32) -> () { + x = x + 1; + } + fn main() -> () { + a(5+2); + } ``` #### Showcase step by step @@ -555,7 +561,7 @@ fn b() -> bool { ##### Conditional command ```math -\frac{<e,σ> → \text{ bool } <c0,σ> → t}{<\text{ if e then } c0 \text{ else } c1,σ> → t}, where t = type of last statement +\frac{<e,σ> → \text{ bool } <c0,σ> → t}{<\text{ if e then } c0 \text{ else } c1,σ> → t}, \text{ where t = type of last statement } ``` For the if statement to go through the type checker need the expression, e, be a boolean. @@ -586,10 +592,22 @@ The example above is valid for the type checker due to it only checking that the ##### Functioncall ```math -\frac{}{}; +\frac{(<e_1,σ> → t1 ... <e_i,σ> → ti)}{<c,σ> → t_res}, \text{ where t_res = return type of function } ``` +Each expression evaluating to the same type as the arguments connected to the function. + ```rust + fn a(x: i32) -> bool { + x < 5; + } + fn b(x: bool, y: i32) -> () { + x = x + 1; + } + fn main() -> () { + a(5+2); // Valid + b(true, 5 < 7); //Invalid for type checker + } ``` #### Coverage -- GitLab