• Keine Ergebnisse gefunden

The function map

N/A
N/A
Protected

Academic year: 2021

Aktie "The function map"

Copied!
3
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

1

(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

2

(3)

The function foldr

sum :: Num a => [a] -> a prod :: Num a => [a] -> a

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 :: Num a => [a] -> a prod :: Num a => [a] -> a

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

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

concat = foldr (++) []

3

Referenzen

ÄHNLICHE DOKUMENTE

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

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

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

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

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