Compare commits

...

3 Commits

Author SHA1 Message Date
Gregory Hammond 674da1d686 Merge pull request 'block5' (#1) from block5 into main
Reviewed-on: #1
2025-02-06 08:49:50 +01:00
1925458 2de11701a8 removed a mistake 2025-02-05 23:41:39 +01:00
1925458 482042ce88 added 4 & 5 2025-02-05 23:32:11 +01:00
5 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,17 @@
doubleAndIncrement :: Int -> Int
--
-- AUFGABE BEGINNT HIER
--
doubleAndIncrement =
--
-- AUFGABE ENDET HIER
--
-- Test cases
main = do
print (doubleAndIncrement 3) -- 7
print (doubleAndIncrement 5) -- 11

View File

@ -0,0 +1,20 @@
multiplyBy :: Int -> (Int -> Int)
double :: Int -> Int
--
-- AUFGABE BEGINNT HIER
--
multiplyBy = -- Fill in
double = -- Fill in using partial application
triple = -- Fill in using partial application
--
-- AUFGABE ENDET HIER
--
-- Test cases
main = do
print (double 4) -- Expected output: 8
print (double 7) -- Expected output: 14
print (triple 4) -- Expected output: 12

View File

@ -0,0 +1,22 @@
addThreeNumbers :: Int -> Int -> Int -> Int
addFive :: Int -> Int -> Int
--
-- AUFGABE BEGINNT HIER
--
addThreeNumbers = -- Fill in
addFive = -- Fill in using partial application
--
-- AUFGABE ENDET HIER
--
-- Test cases
main = do
print (addThreeNumbers 3 2 4) -- 9
print (addThreeNumbers 7 6 4) -- 17
print (addFive 3 2) -- 10
print (addFive 1 4) -- 10

View File

@ -0,0 +1,21 @@
module Main where
-- Definiert einen simplen container für unsere Werte
data Box a = Box a deriving (Show, Eq)
-- Schreibe die Unit funktion, welche einen Wert in einen Container verschachtelt!
unit :: a -> Box a
-- Schreibe die Bind Funktion, welches es einem Erlaubt
bind :: Box a -> (a -> Box b) -> Box b
-- Schreibe eine Lift Funktion, welche eine Funtion nimmt und diesselbe funktion mit den Monadischen Werten als Eigabe und Ausgabetyp besitzt
lift :: (a -> b) -> Box a -> Box b
-- Main Function to run tests
main :: IO ()
main = do
print $ unit 10 -- Box 10

View File

@ -0,0 +1,21 @@
module Main where
-- Definiere eine einfache Datenstruktur für DOM-Elemente
data DOM a = Element a [DOM a] | EmptyElement deriving (Show, Eq)
-- Schreibe die Unit funktion, welche einen Wert in einen DOM-Container verschachtelt!
unit :: a -> DOM a
-- Schreibe die Bind Funktion, welches es einem Erlaubt funktionen des Monadischen Typen DOM zu verketten
bind :: DOM a -> (a -> DOM b) -> DOM b
-- Schreibe eine Lift Funktion, welche eine Funtion nimmt und diesselbe funktion mit den Monadischen Werten DOM als Eigabe und Ausgabetyp besitzt
lift :: (a -> b) -> DOM a -> DOM b
-- Hauptfunktion zum Ausführen von Tests
main :: IO ()
main = do
print $ unit "root" -- Element "root" []