Solve last task
This commit is contained in:
parent
7676005844
commit
4503171ec3
2 changed files with 10 additions and 8 deletions
|
@ -114,7 +114,7 @@ circumference shape = case shape of
|
||||||
{- Exercise
|
{- Exercise
|
||||||
Define a function
|
Define a function
|
||||||
'area :: Shape -> Float'
|
'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.
|
cases such as in 'Case 1' above.
|
||||||
-}
|
-}
|
||||||
area :: Shape -> Float
|
area :: Shape -> Float
|
||||||
|
@ -151,7 +151,7 @@ myFunc x =
|
||||||
x + 1
|
x + 1
|
||||||
|
|
||||||
{- Where
|
{- 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.
|
follow a "main" declaration.
|
||||||
-}
|
-}
|
||||||
six :: Integer
|
six :: Integer
|
||||||
|
|
|
@ -62,8 +62,10 @@ fIfElse n =
|
||||||
|
|
||||||
|
|
||||||
fGuard :: Integer -> String
|
fGuard :: Integer -> String
|
||||||
fGuard = error "fixme"
|
fGuard x
|
||||||
|
| (x `mod` 2 == 0) = "Even"
|
||||||
|
| (x `mod` 3 == 0) = "Odd"
|
||||||
|
| otherwise = "Oddity"
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
-- Cases and pattern matching
|
-- Cases and pattern matching
|
||||||
|
@ -113,12 +115,12 @@ circumference shape = case shape of
|
||||||
{- Exercise
|
{- Exercise
|
||||||
Define a function
|
Define a function
|
||||||
'area :: Shape -> Float'
|
'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.
|
cases such as in 'Case 1' above.
|
||||||
-}
|
-}
|
||||||
area :: Shape -> Float
|
area :: Shape -> Float
|
||||||
area = error "fixme"
|
area (Rectangle length width) = width * length
|
||||||
|
area (Circle radius) = (radius ^ 2) * pi
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
-- Let and where
|
-- Let and where
|
||||||
|
@ -149,7 +151,7 @@ myFunc x =
|
||||||
x + 1
|
x + 1
|
||||||
|
|
||||||
{- Where
|
{- 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.
|
follow a "main" declaration.
|
||||||
-}
|
-}
|
||||||
six :: Integer
|
six :: Integer
|
||||||
|
|
Loading…
Reference in a new issue