module Main where -- Definiere eine einfache Datenstruktur für DOM-Elemente data DOM a = Element a [DOM a] | EmptyElement deriving (Show, Eq) -- Unit-Funktion: Verpackt einen Tag in einen DOM Element unit :: a -> DOM a unit x = Element x [] -- Bind-Funktion: Verknüpft Berechnungen für DOM-Elemente 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-Funktion: Hebt eine normale Funktion in den DOM-Kontext lift :: (a -> b) -> DOM a -> DOM b lift _ EmptyElement = EmptyElement lift f (Element x children) = Element (f x) (map (lift f) children) -- Hauptfunktion zum Ausführen von Tests main :: IO () main = do print $ unit "root" -- Element "root" []