Home
 

Wiederaufnahme der Beispiele 3.2 und 3.3

Wiederaufnahme der Beispiele 3.2 und 3.3

Jetzt dasselbe mit HOFs!

  • insertion sort:
     iSort2:: Ord a => [a]->[a]
    
    iSort2 = foldr into []

    also: iSort2 [x1...xn] = x1 `into` ( x2 `into` (...xn `into` [])...)

  • Datenbank
    • replace ist Kandidat für map, weil Elemente der Liste verändert werden;
    • locations ist Kandidat für:
      • erst filter zum Herauslösen der Einträge mit gesuchter Hardware
      • dann map für Projektion der verbleibenden Elemente auf Raum-Komponente
    • how_many: ähnlich
     -------Alternativformulierung mit higher order functions
    
    --------------------------------


    is_wanted:: Hardware->(Hardware,Room)->Bool
    is_wanted h (h',r) = h == h'


    locations2:: Hardware->HwList->[Room]
    locations2 h = map snd . filter (is_wanted h)


    --------------------------------
    -dasselbe mit operator section


    locations3:: Hardware->HwList->[Room]
    locations3 h = map snd . filter ((== h).fst)


    --------------------------------
    --------------------------------


    exchange:: Hardware->Hardware->(Hardware,Room)->(Hardware,Room)
    exchange h h' (h'',r)
    |h == h'' = (h',r)
    |otherwise = (h'',r)


    replace2:: Hardware->Hardware->HwList->HwList
    replac2 h h' = map (exchange h h')
    --------------------------------


    - how_many: Hausaufgabe!



Ronald Blaschke
1998-04-19