# HG changeset patch # User Markus Kaiser # Date 1354138949 -3600 # Node ID 7acf82c8fb3a3b88ce83ab5fcb739238b6e496cb # Parent bef891fc07b4125ffa6e98fc0bdc09ffaa9299ff week 7 diff -r bef891fc07b4 -r 7acf82c8fb3a blatt7.pdf Binary file blatt7.pdf has changed diff -r bef891fc07b4 -r 7acf82c8fb3a exercises/src/Exercise_7.hs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exercises/src/Exercise_7.hs Wed Nov 28 22:42:29 2012 +0100 @@ -0,0 +1,160 @@ +{-# LANGUAGE DeriveGeneric #-} +module Exercise_7 where +import Data.List hiding (insert) +import Data.Char +import Test.QuickCheck + +{- Library DO NOT CHANGE -} +data Tree a = + Empty | + Node a (Tree a) (Tree a) + deriving (Eq, Show) + +data Html = + Text String | + Block String [Html] + +swissLetters :: [(Int, String)] +swissLetters = + [(196, "Auml"), (214, "Ouml"), (220, "Uuml"), + (228, "auml"), (246, "ouml"), (252, "uuml")] + +grueezi = + Block "html" + [Block "head" + [Block "author" [Text "der MC"], + Block "date" [Text "27.11.2012"], + Block "topsecret" []], + Block "body" + [Block "h1" [Text "Gr\252ezi!"], + Block "p" [Text "\196b\228, genau. Sal\252. Bis sp\246ter!"]]] + +data DirTree a = + File a | + Dir a [DirTree a] + deriving (Eq, Show) + +exDir :: DirTree String +exDir = + Dir "" [Dir "usr" [Dir "lib" [File "vim"], Dir "include" [File "string.h"]], + Dir "bin" $ [File "ls", File "cat"]] +{- End Library -} + + +{---------------------------------------------------------------------} +{- Aufgabe G7.1 -} + +{- 1. -} +data WildChar = + Missing + + +data WildPat = + WildPat [WildChar] + + +{- 2. -} +stringFromWildChar :: WildChar -> String +stringFromWildChar = undefined + + +stringFromWildPat :: WildPat -> String +stringFromWildPat (WildPat ws) = undefined + + +{- 3. -} +instance Show WildChar where + show = stringFromWildChar + +instance Show WildPat where + show = stringFromWildPat + + +{- 4. -} +wildCharsFromString :: String -> [WildChar] +wildCharsFromString = undefined + +wildPatFromString :: String -> WildPat +wildPatFromString cs = WildPat (wildCharsFromString cs) + + +{- 5. -} +prop_stringFromWildPatFromString s = undefined + +prop_wildPatFromStringFromWildPat p = undefined + + +{- 6. -} +{- +G4.4 + +match [] ys = null ys +match ('?':ps) (y:ys) = match ps ys +match ('*':ps) [] = match ps [] +match ('*':ps) (y:ys) = match ps (y:ys) || match ('*':ps) ys +match (p:ps) (y:ys) = p == y && match ps ys +match ps [] = False +-} + +matchWildChars :: [WildChar] -> String -> Bool +matchWildChars = undefined + + +matchWildPat :: WildPat -> String -> Bool +matchWildPat (WildPat ws) = matchWildChars ws + +match = matchWildPat . wildPatFromString + + + +{---------------------------------------------------------------------} +{- Aufgabe G7.2 -} + +insert :: Ord a => a -> Tree a -> Tree a +insert x Empty = Node x Empty Empty +insert x (Node a l r) + | x < a = Node a (insert x l) r + | a < x = Node a l (insert x r) + | otherwise = Node a l r + + +treeSort :: Ord a => [a] -> [a] +treeSort = undefined + + + +{---------------------------------------------------------------------} +{- Aufgabe G7.3 -} + +plainHtml :: Html -> String +plainHtml = undefined + + + +{---------------------------------------------------------------------} +{- Aufgabe H7.1 -} + +prettyHtml :: Int -> Html -> String +prettyHtml = undefined + + + +{---------------------------------------------------------------------} +{- Aufgabe H7.2 -} + +plainDirTree :: Show a => DirTree a -> String +plainDirTree = undefined + + +prettyDirTree :: Show a => DirTree a -> String +prettyDirTree = undefined + + + +{---------------------------------------------------------------------} +{- Aufgabe H7.3 -} + +{-WETT-} +unscrambleWords :: [String] -> [String] -> [String] +unscrambleWords = undefined +{-TTEW-}