Compare commits

..

No commits in common. "4580f58d9a5e88402ebae7cdf4c164b5255d06a3" and "950be7fa7bb30ef49af37dc66b2236ee172f8076" have entirely different histories.

2 changed files with 2 additions and 20 deletions

View file

@ -63,7 +63,6 @@ zoe = Car {
sorted = sort [zoe, ferrari, ford]
-- >>> sorted
-- [Car {model = Model "Fiesta", make = Make "Ford", year = 2017, color = RGB {r = 255, g = 0, b = 0}, power = 70},Car {model = Model "Testarossa", make = Make "Ferrari", year = 1991, color = RGB {r = 0, g = 255, b = 0}, power = 27},Car {model = Model "Zoe", make = Make "Renault", year = 2023, color = RGB {r = 255, g = 255, b = 255}, power = 70}]
--
--------------------
-- Exercise 2
@ -105,7 +104,6 @@ tree =
-- >>> show tree
-- "PolyTree 1 [PolyTree 2 [PolyTree 5 [],PolyTree 6 [],PolyTree 7 []],PolyTree 3 [PolyTree 8 []]]"
--
--------------------
-- Exercise 3
@ -123,10 +121,8 @@ eval x =
-- >>> Z
-- Z
--
-- >>> eval $ S $ S $ S Z
-- >>> eval (S (S (S Z)))
-- 3
--
uneval :: Integer -> NatNumber
uneval x
@ -135,19 +131,13 @@ uneval x
| otherwise = S (uneval (x - 1))
-- >>> uneval (-1)
-- *** Exception: negative numbers are not natural numbers
-- CallStack (from HasCallStack):
-- error, called at /home/manuel/Documents/Repositories/zhaw-fup/Exercises/exercise-2/Solution.hs:133:15 in main:Main
--
-- negative numbers are not natural numbers
-- >>> uneval 0
-- Z
--
-- >>> uneval 1
-- S Z
--
-- >>> uneval 3
-- S (S (S Z))
--
addNat :: NatNumber -> NatNumber -> NatNumber
addNat a b =
@ -157,7 +147,6 @@ addNat a b =
-- >>> eval (addNat (uneval 7) (uneval 2))
-- 9
--
mulNat :: NatNumber -> NatNumber -> NatNumber
mulNat a b =
@ -167,7 +156,6 @@ mulNat a b =
-- >>> eval (mulNat (uneval 3) (uneval 2))
-- 6
--
fact :: NatNumber -> NatNumber
fact x =
@ -177,10 +165,8 @@ fact x =
-- >>> eval (fact Z)
-- 1
--
-- >>> eval (fact (S (S Z)))
-- 2
--
--------------------
-- Exercise 4
@ -217,4 +203,3 @@ fibProgram =
-- Should evaluate to True
-- >>> sum (execute fibProgram 31250) == 26183978971946924
-- True
--

BIN
Exercises/exercise-3/exercise-3.pdf (Stored with Git LFS)

Binary file not shown.