lab04b: init

This commit is contained in:
2026-02-11 11:27:00 -08:00
parent 9a8d2abfdb
commit 2943b49182
6 changed files with 182 additions and 0 deletions

14
lab04/tailRecursion.hs Normal file
View File

@@ -0,0 +1,14 @@
fact :: Integer -> Integer
fact 1 = 1
fact n = n * (fact $ n - 1)
fact' :: Integer -> Integer -> Integer
fact' 0 acc = acc
fact' n acc = fact' (n - 1) (n * acc)
fact2 :: Integer -> Integer -> Integer
fact2 n acc = if n == 0
then acc
else fact2 (n - 1) (n * acc)