next up previous contents
Next: Beispiel: Sortieren durch Einfügen Up: Listen Previous: Listen

Elementares

$\Rightarrow$ Standard Prelude A1, Report Seite 96 ff. enthält viele weitere Definitionen, einiges daraus später!

Beispiel PreludeList aus dem Standard-Prelude:

 -  A.1  Prelude PreludeList


- Standard list functions
module PreludeList (
head, last, tail, init, null, length, (!!),
foldl, foldl1, scanl, scanl1, foldr, foldr1, scanr, scanr1,
iterate, repeat, replicate, cycle,
take, drop, splitAt, takeWhile, dropWhile, span, break,
lines, words, unlines, unwords, reverse, and, or,
any, all, elem, notElem, lookup,
sum, product, maximum, minimum, concatMap,
zip, zip3, zipWith, zipWith3, unzip, unzip3)
where


import qualified Char(isSpace)


infixl 9 !!
infix 4 `elem`, `notElem`


- head and tail extract the first element and remaining elements,
- respectively, of a list, which must be non-empty. last and init
- are the dual functions working from the end of a finite list,
- rather than the beginning.
head :: [a] -> a
head (x:_) = x
head [] = error "PreludeList.head: empty list"


last :: [a] -> a
last [x] = x
last (_:xs) = last xs
last [] = error "PreludeList.last: empty list"


tail :: [a] -> [a]
tail (_:xs) = xs
tail [] = error "PreludeList.tail: empty list"


init :: [a] -> [a]
init [x] = []
init (x:xs) = x : init xs
init [] = error "PreludeList.init: empty list"


null :: [a] -> Bool
null [] = True
null (_:_) = False


- length returns the length of a finite list as an Int.
length :: [a] -> Int
length [] = 0
length (_:l) = 1 + length l
...


next up previous contents
Next: Beispiel: Sortieren durch Einfügen Up: Listen Previous: Listen
Ronald Blaschke
1998-04-19