-- Beispiel für Funktionen mit einer Funktion als Ergebnis -- Fläche eines Rechtecks mit Seiten a und b fläche :: Float -> (Float -> Float) fläche a b = a * b -- Gegeben sei die Länge l einer Terasse T l :: Float l = 3.4 -- Berechne die Fläche dieser Terasse in Abhängigkeit der Breite flächeT :: Float -> Float flächeT = fläche l -- Beispiel für Funktionen mit einer Funktion als Argument -- Berechne den Schnittpunkt einer einstelligen Funktion mit der Y-Achse schnittY :: (Float -> Float) -> Float schnittY f = f 0 -- Beispiel für Funktionen mit einer Funktion als Argument -- und einer Funktion als Ergebnis doppelt :: (Float -> Float) -> (Float -> Float) doppelt f x = f (f x) hoch2, hoch4 :: Float -> Float hoch2 x = x*x hoch4 = doppelt hoch2 -- Beispiele für die verwendung von Typvariablen doppelt' :: (t -> t) -> (t -> t) doppelt' f x = f (f x) hoch4' :: Float -> Float hoch4' = doppelt' hoch2 vertausche :: (v,w) -> (w,v) vertausche (a,b) = (b,a) {- Beispielauswertung: Main> vertausche ('V','W') ('W','V') -} -- Beispiel für Sektionen halbiere :: Float -> Float halbiere = (/2) einViertel :: Float -> Float einViertel = doppelt halbiere {- Beispielauswertung: Main> einViertel 24 6.0 -}