view exercises/src/Exercise_5.hs @ 12:8496af3b866b

add G5.3 and G5.4 definitions
author Markus Kaiser <markus.kaiser@in.tum.de>
date Wed, 14 Nov 2012 19:13:22 +0100
parents a721abd5a135
children 8cc37c82619c
line wrap: on
line source

module Exercise_5 where
import Data.Maybe

{- Library DO NOT CHANGE -}
type State = Integer
type DA = (State, State -> Char -> State, State -> Bool)
type ListDA = (State, [((State, Char), State)], [State])

a :: DA
a = (0, delta, (==1))
  where
    delta 0 'a' = 1
    delta 1 'a' = 1
    delta 2 'a' = 1
    delta 0 'b' = 2
    delta 1 'b' = 2
    delta 2 'b' = 2

toDA :: ListDA -> DA
toDA (start, delta, final) = (start, deltaFun delta, (`elem` final))
  where deltaFun dl = curry (fromMaybe 0 . flip lookup dl)
{- End Library -}


{---------------------------------------------------------------------}
{- Aufgabe G5.1 -}

iter :: Int -> (a -> a) -> a -> a
iter n f x = undefined


pow :: Int -> Int -> Int
pow n k = undefined


drop' :: Int -> [a] -> [a]
drop' n xs = undefined


replicate' :: Int -> a -> [a]
replicate' n x = undefined



{---------------------------------------------------------------------}
{- Aufgabe G5.2 -}

partition_rec :: (a -> Bool) -> [a] -> ([a], [a])
partition_rec p xs = undefined


partition_foldr :: (a -> Bool) -> [a] -> ([a], [a])
partition_foldr p xs = undefined


partition_filter :: (a -> Bool) -> [a] -> ([a], [a])
partition_filter p xs = undefined


zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' f xs ys = undefined



{---------------------------------------------------------------------}
{- Aufgabe G5.3 -}

lambda_1 = (\xs -> foldr (++) [] (map (\x -> [x]) xs))
lambda_2 = (\gg xx yy -> head (tail (zipWith gg [ xx , xx ] [ yy , yy ])))



{---------------------------------------------------------------------}
{- Aufgabe G5.4 -}

zeros :: [Int] 
zeros = 0 : zeros 


length' :: [a] -> Int 
length' [] = 0 
length' (_:xs) = 1 + length' xs 


h :: Integer -> Integer -> Integer
h m n
        | m == n = 0
        | m < n = h m (n - 1)
        | m >= n = h n m + 1



{---------------------------------------------------------------------}
{- Aufgabe H5.1 -}

fixpoint :: (a -> a -> Bool) -> (a -> a) -> a -> a
fixpoint = undefined


cents :: [Integer] -> [Integer]
cents = undefined


trancl :: [(Integer, Integer)] -> [(Integer, Integer)]
trancl = undefined



{---------------------------------------------------------------------}
{- Aufgabe H5.2 -}

advance :: DA -> State -> String -> State
advance = undefined


prop_advance_empty :: ListDA -> State -> Bool
prop_advance_empty = undefined


prop_advance_single :: ListDA -> State -> Char -> Bool
prop_advance_single = undefined


prop_advance_concat :: ListDA -> State -> String -> String -> Bool
prop_advance_concat = undefined


accept :: DA -> String -> Bool
accept = undefined


reachableStates :: DA -> State -> [Char] -> [State]
reachableStates = undefined



{---------------------------------------------------------------------}
{- Aufgabe H5.3 -}

{-WETT-}
quasiSubseq :: Eq a => [a] -> [a] -> Bool
quasiSubseq xs ys = undefined
{-TTEW-}