removed a mistake
parent
482042ce88
commit
2de11701a8
|
@ -1,28 +1,21 @@
|
||||||
-- Haskell Exercise: Implementing Bind, Unit, and Lift for a DOM-like Structure
|
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
-- Define a simple data type for DOM Elements
|
-- Definiere eine einfache Datenstruktur für DOM-Elemente
|
||||||
data DOM a = Element a [DOM a] | EmptyElement deriving (Show, Eq)
|
data DOM a = Element a [DOM a] | EmptyElement deriving (Show, Eq)
|
||||||
|
|
||||||
-- Unit function: Wraps a value in the DOM type
|
-- Schreibe die Unit funktion, welche einen Wert in einen DOM-Container verschachtelt!
|
||||||
unit :: a -> DOM a
|
unit :: a -> DOM a
|
||||||
unit x = Element x []
|
|
||||||
|
|
||||||
-- Bind function: Chains computations on DOM elements
|
|
||||||
|
-- Schreibe die Bind Funktion, welches es einem Erlaubt funktionen des Monadischen Typen DOM zu verketten
|
||||||
bind :: DOM a -> (a -> DOM b) -> DOM b
|
bind :: DOM a -> (a -> DOM b) -> DOM b
|
||||||
bind EmptyElement _ = EmptyElement
|
|
||||||
bind (Element x children) f =
|
|
||||||
case f x of
|
|
||||||
EmptyElement -> EmptyElement
|
|
||||||
Element newX newChildren -> Element newX (newChildren ++ map (`bind` f) children)
|
|
||||||
|
|
||||||
-- Lift function: Lifts a normal function into the DOM context
|
|
||||||
|
-- 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
|
lift :: (a -> b) -> DOM a -> DOM b
|
||||||
lift _ EmptyElement = EmptyElement
|
|
||||||
lift f (Element x children) = Element (f x) (map (lift f) children)
|
|
||||||
|
|
||||||
-- Main Function to run tests
|
|
||||||
|
-- Hauptfunktion zum Ausführen von Tests
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
print $ unit "root" -- Should print Element "root" []
|
print $ unit "root" -- Element "root" []
|
Loading…
Reference in New Issue