Presentation is loading. Please wait.

Presentation is loading. Please wait.

Koen Lindström Claessen

Similar presentations


Presentation on theme: "Koen Lindström Claessen"— Presentation transcript:

1 Koen Lindström Claessen
Listor Koen Lindström Claessen

2 Recursiva Datatyper data List a = Empty | Add a (List a) data [a] = []
uttal: ”cons”

3 Notation list-type length :: [a] -> Int list with one element [12]
12 : [] [12, 0, 3, 17, 123] 12 : (0 : (3 : (17 : (123 : []))))

4 Quiz Vad är typen på funktionen [] ? Vad är typen på funktionen (:) ?
(:) :: a -> [a] -> [a]

5 Programming Examples length (size) maximum (mest) (++) (+++)
reverse (rev) (see file Lists.hs)

6 Do’s and Don’ts Do not make unnecessary case distinctions
fun1 :: [Integer] -> Bool fun1 [] = False fun1 (x:xs) = length (x:xs) == 10 repeated code fun1 :: [Integer] -> Bool fun1 xs = length xs == 10

7 Make the base case as simple as possible
Do’s and Don’ts right base case ? fun2 :: [Integer] -> Integer fun2 [x] = calc x fun2 (x:xs) = calc x + fun2 xs repeated code fun2 :: [Integer] -> Integer fun2 [] = 0 fun2 (x:xs) = calc x + fun2 xs


Download ppt "Koen Lindström Claessen"

Similar presentations


Ads by Google