###### Sprachumschaltung

Sie sind hier: Übung 00

# Übung 00

Wiederholung: Funktionen und Listen Recap.hs — Haskell source code, 1 KB (1914 bytes)

## Dateiinhalt

```-- | Functional Programming, course at LMU, summer term 2012
--   Andreas Abel and Steffen Jost
--
-- Exercise sheet 0, 2012-04-17

{-# LANGUAGE TemplateHaskell #-} -- for QuickCheck.All

module Recap where

import Prelude hiding (id,curry,uncurry,flip,
(++),map,zipWith,zip,zipWith3,foldr,foldl,reverse)
import Test.QuickCheck
import Test.QuickCheck.All

-- Implement the following functions, replacing @undefined@.

-- * Lambda-calculus

id :: a -> a
id = undefined

(|>) :: a -> (a -> b) -> b
(|>) = undefined

(||>) :: (a,b) -> (a -> b -> c) -> c
(||>) = undefined

curry :: ((a,b) -> c) -> (a -> b -> c)
curry = undefined

uncurry :: (a -> b -> c) -> ((a,b) -> c)
uncurry = undefined

flip :: (a -> b -> c) -> (b -> a -> c)
flip = undefined

-- * Lists

-- | Concatenating lists @[1..n] ++ [n+1..n+m] == [1..n+m]@
(++) :: [a] -> [a] -> [a]
(++) = undefined

map :: (a -> b) -> [a] -> [b]
map = undefined

zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith = undefined

zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3 = undefined

zip :: [a] -> [b] -> [(a,b)]
zip = undefined

foldr :: (a -> b -> b) -> b -> [a] -> b
foldr = undefined

foldl :: (b -> a -> b) -> b -> [a] -> b
foldl = undefined

-- | @reverseAppend [n,n-1..1] [n+1..n+m] == [1..n+m]@
reverseAppend :: [a] -> [a] -> [a]
reverseAppend = undefined

-- | @reverse [1..n] == [n,n-1..1]@
reverse :: [a] -> [a]
reverse = undefined

-- * Tests

prop_map (NonNegative n) (NonNegative m) =
map (+ m) [1..n] == [1+m..n+m]

prop_zipWith (NonNegative n) (NonNegative m) =
zipWith (-) [n+1..n+m] (repeat n) == [1..m]

prop_foldr l = foldr (:) [] l == l
prop_foldl l = foldl (flip (:)) [] l == reverse l

prop_reverseAppend (NonNegative n) (NonNegative m) =
reverseAppend [n,n-1..1] [n+1..n+m] == [1..n+m]

prop_reverse (NonNegative n) =
reverse [1..n] == [n,n-1..1]

-- | Execute @runTests@ in GHCi
runTests = \$quickCheckAll
```

Artikelaktionen