• Keine Ergebnisse gefunden

The function map

N/A
N/A
Protected

Academic year: 2021

Aktie "The function map"

Copied!
4
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

The function map

suclist :: [Int] -> [Int]

suclist [] = []

suclist (x:xs) = suc x : suclist xs sqrtlist :: [Float] -> [Float]

sqrtlist [] = []

sqrtlist (x:xs) = sqrt x : sqrtlist xs map :: (a -> b) -> [a] -> [b]

map g [] = []

map g (x:xs) = g x : map g xs

suclist :: [Int] -> [Int] sqrtlist :: [Float] -> [Float]

suclist = map suc sqrtlist = map sqrt

21

(2)

The function filter

dropEven :: [Int] -> [Int]

dropEven [] = []

dropEven (x:xs) | odd x = x : dropEven xs

| otherwise = dropEven xs dropUpper :: [Char] -> [Char]

dropUpper [] = []

dropUpper (x:xs) | isLower x = x : dropUpper xs

| otherwise = dropUpper xs filter :: (a -> Bool) -> [a] -> [a]

filter g [] = []

filter g (x:xs) | g x = x : filter g xs

| otherwise = filter g xs

dropEven :: [Int] -> [Int] dropUpper :: [Char] -> [Char]

dropEven = filter odd dropUpper = filter isLower

22

(3)

The function fold

add :: (List Int) -> Int prod :: (List Int) -> Int

add Nil = 0 prod Nil = 1

add (Cons x xs) = plus x (add xs) prod (Cons x xs) = times x (prod xs) concat :: List (List a) -> List a

concat Nil = Nil

concat (Cons x xs) = append x (concat xs) fold :: (a -> b -> b) -> b -> (List a) -> b

fold g e Nil = e

fold g e (Cons x xs) = g x (fold g e xs)

add :: (List Int) -> Int prod :: (List Int) -> Int

add = fold plus 0 prod = fold times 1

concat :: List (List a) -> List a concat = fold append Nil

23

(4)

The function foldr

sum :: [Int] -> Int prod :: [Int] -> Int

sum [] = 0 prod [] = 1

sum (x:xs) = x + sum xs prod (x:xs) = x * prod xs concat :: [[a]] -> [a]

concat [] = []

concat (x:xs) = x ++ concat xs foldr :: (a -> b -> b) -> b -> [a] -> b foldr g e [] = e

foldr g e (x:xs) = g x (foldr g e xs)

sum :: [Int] -> Int prod :: [Int] -> Int

sum = foldr (+) 0 prod = foldr (*) 1

concat :: [[a]] -> [a]

concat = foldr (++) []

24

Referenzen

ÄHNLICHE DOKUMENTE

A “value map” consists of indifference curves, drawn in price-quality space, that represent indifferent combinations of price and quality for a consumer (or a group of

In recent years, information on peatland distribution within the countries of Europe has been compiled by the Greifswald Mire Centre (GMC) in the process of producing

Whilst gross employment destruction originated by firm exit is 8 per cent for transition economies, that same indicator has a value of 4 per cent in the case of Western

[r]

We describe a system for online map matching in the backend that implements a state of the art algorithm based on a Hidden Markov Model.. This system uses only open source software

The cc2test command executes a data transfer test from central memory to the I/O buffer board (lOBB) and back to central memory.. Test initialization includes loading

At the same time Finnish defence plan- ners were constantly aware that Estonia.. and Latvia might be occupied by the USSR. In the second half of the 1930s, with Finland

By a suitable application of the Fourier transform, there exists a close connection between this problem and the surjectivity or injectivity of the asymptotic Borel map