Update output to new version

This commit is contained in:
Manuel Thalmann 2024-06-15 18:14:42 +02:00
parent d8f7056f96
commit 4580f58d9a

View file

@ -63,6 +63,7 @@ zoe = Car {
sorted = sort [zoe, ferrari, ford] sorted = sort [zoe, ferrari, ford]
-- >>> sorted -- >>> 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}] -- [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 -- Exercise 2
@ -104,6 +105,7 @@ tree =
-- >>> show tree -- >>> show tree
-- "PolyTree 1 [PolyTree 2 [PolyTree 5 [],PolyTree 6 [],PolyTree 7 []],PolyTree 3 [PolyTree 8 []]]" -- "PolyTree 1 [PolyTree 2 [PolyTree 5 [],PolyTree 6 [],PolyTree 7 []],PolyTree 3 [PolyTree 8 []]]"
--
-------------------- --------------------
-- Exercise 3 -- Exercise 3
@ -121,8 +123,10 @@ eval x =
-- >>> Z -- >>> Z
-- Z -- Z
--
-- >>> eval $ S $ S $ S Z -- >>> eval $ S $ S $ S Z
-- 3 -- 3
--
uneval :: Integer -> NatNumber uneval :: Integer -> NatNumber
uneval x uneval x
@ -131,13 +135,19 @@ uneval x
| otherwise = S (uneval (x - 1)) | otherwise = S (uneval (x - 1))
-- >>> uneval (-1) -- >>> uneval (-1)
-- negative numbers are not natural numbers -- *** 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
--
-- >>> uneval 0 -- >>> uneval 0
-- Z -- Z
--
-- >>> uneval 1 -- >>> uneval 1
-- S Z -- S Z
--
-- >>> uneval 3 -- >>> uneval 3
-- S (S (S Z)) -- S (S (S Z))
--
addNat :: NatNumber -> NatNumber -> NatNumber addNat :: NatNumber -> NatNumber -> NatNumber
addNat a b = addNat a b =
@ -147,6 +157,7 @@ addNat a b =
-- >>> eval (addNat (uneval 7) (uneval 2)) -- >>> eval (addNat (uneval 7) (uneval 2))
-- 9 -- 9
--
mulNat :: NatNumber -> NatNumber -> NatNumber mulNat :: NatNumber -> NatNumber -> NatNumber
mulNat a b = mulNat a b =
@ -156,6 +167,7 @@ mulNat a b =
-- >>> eval (mulNat (uneval 3) (uneval 2)) -- >>> eval (mulNat (uneval 3) (uneval 2))
-- 6 -- 6
--
fact :: NatNumber -> NatNumber fact :: NatNumber -> NatNumber
fact x = fact x =
@ -165,8 +177,10 @@ fact x =
-- >>> eval (fact Z) -- >>> eval (fact Z)
-- 1 -- 1
--
-- >>> eval (fact (S (S Z))) -- >>> eval (fact (S (S Z)))
-- 2 -- 2
--
-------------------- --------------------
-- Exercise 4 -- Exercise 4
@ -203,3 +217,4 @@ fibProgram =
-- Should evaluate to True -- Should evaluate to True
-- >>> sum (execute fibProgram 31250) == 26183978971946924 -- >>> sum (execute fibProgram 31250) == 26183978971946924
-- True -- True
--