From 4503171ec38f63a12211df5711e179734f0f16f3 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 14 Mar 2024 18:34:27 +0100 Subject: [PATCH] Solve last task --- Exercises/exercise-1/Code/D_Control.hs | 4 ++-- Exercises/exercise-1/Code/D_ControlTodo.hs | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Exercises/exercise-1/Code/D_Control.hs b/Exercises/exercise-1/Code/D_Control.hs index 899549d..ed78152 100644 --- a/Exercises/exercise-1/Code/D_Control.hs +++ b/Exercises/exercise-1/Code/D_Control.hs @@ -114,7 +114,7 @@ circumference shape = case shape of {- Exercise Define a function 'area :: Shape -> Float' - to compute the area of any given shape. Use spearate + to compute the area of any given shape. Use separate cases such as in 'Case 1' above. -} area :: Shape -> Float @@ -151,7 +151,7 @@ myFunc x = x + 1 {- Where - Where is the same as let, but it does not preceed but + Where is the same as let, but it does not precede but follow a "main" declaration. -} six :: Integer diff --git a/Exercises/exercise-1/Code/D_ControlTodo.hs b/Exercises/exercise-1/Code/D_ControlTodo.hs index 4a1ef06..ec2b9bf 100644 --- a/Exercises/exercise-1/Code/D_ControlTodo.hs +++ b/Exercises/exercise-1/Code/D_ControlTodo.hs @@ -62,8 +62,10 @@ fIfElse n = fGuard :: Integer -> String -fGuard = error "fixme" - +fGuard x + | (x `mod` 2 == 0) = "Even" + | (x `mod` 3 == 0) = "Odd" + | otherwise = "Oddity" ----------------------------------------------------------- -- Cases and pattern matching @@ -113,12 +115,12 @@ circumference shape = case shape of {- Exercise Define a function 'area :: Shape -> Float' - to compute the area of any given shape. Use spearate + to compute the area of any given shape. Use separate cases such as in 'Case 1' above. -} area :: Shape -> Float -area = error "fixme" - +area (Rectangle length width) = width * length +area (Circle radius) = (radius ^ 2) * pi ----------------------------------------------------------- -- Let and where @@ -149,7 +151,7 @@ myFunc x = x + 1 {- Where - Where is the same as let, but it does not preceed but + Where is the same as let, but it does not precede but follow a "main" declaration. -} six :: Integer