Mercurial > 12ws.info2
view exercises/src/Exercise_7.hs @ 16:7acf82c8fb3a
week 7
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Wed, 28 Nov 2012 22:42:29 +0100 |
parents | |
children | 73170284e009 |
line wrap: on
line source
{-# 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-}