Lösungen zu den Übungen aus  Kapitel 1

 

Übung 1 Prelude> sum[1..100]
5050
cmTypeOfName: it
it :: Integer

 

Übung 2 Prelude> max 'a' 'c'
'c'
cmTypeOfName: it
it :: Char
 

Prelude> max 'a' 'A'
'a'
cmTypeOfName: it
it :: Char
 

Prelude> max 'a' '1'
'a'
cmTypeOfName: it
it :: Char
 

Prelude> max '9' '0'
'9'
cmTypeOfName: it
it :: Char
 

Prelude> max "Beatles" "Zappa"
"Zappa"
cmTypeOfName: it
it :: [Char]
 

Prelude> max "Anton" "999"
"Anton"
cmTypeOfName: it
it :: [Char]

 

Bemerkungen Unschwer erkennt man, dass ein String nichts anderes als eine Liste von Char ist. Dies ist ganz anders in Java
 
Übung 3 Prelude> max 2 (max 4 1)
4
cmTypeOfName: it
it :: Integer

Auf die Klammer kann nicht verzichtet werden, da von links nach rechts auswertet wird. Würde man auf die Klammern verzichten, würde die erste Funktion max 2 als ersten und max als zweiten Parameter auswerten wollen, was zu einer Fehlermeldung führen muss.

Prelude> max 2 max 4 1

<interactive>:1:
No instances for (Num (a -> a -> a), Ord (a -> a -> a))
arising from the literal `2' at <interactive>:1
In the first argument of `max', namely `2'
In the definition of `it': it = max 2 max 4 1

<interactive>:1:
No instances for (Num (a -> a -> a), Ord (a -> a -> a))
arising from use of `max' at <interactive>:1
In the definition of `it': it = max 2 max 4 1
 

Übung 4 *EigeneFunktionen> (reverse.reverse) "Zappa"
"Zappa"
weiter  zu Kapitel 02: Definition von Funktionen
 


(C) Michael Pohlig 2005   -> www.pohlig.de