16
|
1 {-# LANGUAGE DeriveGeneric #-} |
|
2 module Exercise_7 where |
|
3 import Data.List hiding (insert) |
|
4 import Data.Char |
|
5 import Test.QuickCheck |
|
6 |
|
7 {- Library DO NOT CHANGE -} |
|
8 data Tree a = |
|
9 Empty | |
|
10 Node a (Tree a) (Tree a) |
|
11 deriving (Eq, Show) |
|
12 |
|
13 data Html = |
|
14 Text String | |
|
15 Block String [Html] |
|
16 |
|
17 swissLetters :: [(Int, String)] |
|
18 swissLetters = |
|
19 [(196, "Auml"), (214, "Ouml"), (220, "Uuml"), |
|
20 (228, "auml"), (246, "ouml"), (252, "uuml")] |
|
21 |
|
22 grueezi = |
|
23 Block "html" |
|
24 [Block "head" |
|
25 [Block "author" [Text "der MC"], |
|
26 Block "date" [Text "27.11.2012"], |
|
27 Block "topsecret" []], |
|
28 Block "body" |
|
29 [Block "h1" [Text "Gr\252ezi!"], |
|
30 Block "p" [Text "\196b\228, genau. Sal\252. Bis sp\246ter!"]]] |
|
31 |
|
32 data DirTree a = |
|
33 File a | |
|
34 Dir a [DirTree a] |
|
35 deriving (Eq, Show) |
|
36 |
|
37 exDir :: DirTree String |
|
38 exDir = |
|
39 Dir "" [Dir "usr" [Dir "lib" [File "vim"], Dir "include" [File "string.h"]], |
|
40 Dir "bin" $ [File "ls", File "cat"]] |
|
41 {- End Library -} |
|
42 |
|
43 |
|
44 {---------------------------------------------------------------------} |
|
45 {- Aufgabe G7.1 -} |
|
46 |
|
47 {- 1. -} |
|
48 data WildChar = |
|
49 Missing |
|
50 |
|
51 |
|
52 data WildPat = |
|
53 WildPat [WildChar] |
|
54 |
|
55 |
|
56 {- 2. -} |
|
57 stringFromWildChar :: WildChar -> String |
|
58 stringFromWildChar = undefined |
|
59 |
|
60 |
|
61 stringFromWildPat :: WildPat -> String |
|
62 stringFromWildPat (WildPat ws) = undefined |
|
63 |
|
64 |
|
65 {- 3. -} |
|
66 instance Show WildChar where |
|
67 show = stringFromWildChar |
|
68 |
|
69 instance Show WildPat where |
|
70 show = stringFromWildPat |
|
71 |
|
72 |
|
73 {- 4. -} |
|
74 wildCharsFromString :: String -> [WildChar] |
|
75 wildCharsFromString = undefined |
|
76 |
|
77 wildPatFromString :: String -> WildPat |
|
78 wildPatFromString cs = WildPat (wildCharsFromString cs) |
|
79 |
|
80 |
|
81 {- 5. -} |
|
82 prop_stringFromWildPatFromString s = undefined |
|
83 |
|
84 prop_wildPatFromStringFromWildPat p = undefined |
|
85 |
|
86 |
|
87 {- 6. -} |
|
88 {- |
|
89 G4.4 |
|
90 |
|
91 match [] ys = null ys |
|
92 match ('?':ps) (y:ys) = match ps ys |
|
93 match ('*':ps) [] = match ps [] |
|
94 match ('*':ps) (y:ys) = match ps (y:ys) || match ('*':ps) ys |
|
95 match (p:ps) (y:ys) = p == y && match ps ys |
|
96 match ps [] = False |
|
97 -} |
|
98 |
|
99 matchWildChars :: [WildChar] -> String -> Bool |
|
100 matchWildChars = undefined |
|
101 |
|
102 |
|
103 matchWildPat :: WildPat -> String -> Bool |
|
104 matchWildPat (WildPat ws) = matchWildChars ws |
|
105 |
|
106 match = matchWildPat . wildPatFromString |
|
107 |
|
108 |
|
109 |
|
110 {---------------------------------------------------------------------} |
|
111 {- Aufgabe G7.2 -} |
|
112 |
|
113 insert :: Ord a => a -> Tree a -> Tree a |
|
114 insert x Empty = Node x Empty Empty |
|
115 insert x (Node a l r) |
|
116 | x < a = Node a (insert x l) r |
|
117 | a < x = Node a l (insert x r) |
|
118 | otherwise = Node a l r |
|
119 |
|
120 |
|
121 treeSort :: Ord a => [a] -> [a] |
|
122 treeSort = undefined |
|
123 |
|
124 |
|
125 |
|
126 {---------------------------------------------------------------------} |
|
127 {- Aufgabe G7.3 -} |
|
128 |
|
129 plainHtml :: Html -> String |
|
130 plainHtml = undefined |
|
131 |
|
132 |
|
133 |
|
134 {---------------------------------------------------------------------} |
|
135 {- Aufgabe H7.1 -} |
|
136 |
|
137 prettyHtml :: Int -> Html -> String |
|
138 prettyHtml = undefined |
|
139 |
|
140 |
|
141 |
|
142 {---------------------------------------------------------------------} |
|
143 {- Aufgabe H7.2 -} |
|
144 |
|
145 plainDirTree :: Show a => DirTree a -> String |
|
146 plainDirTree = undefined |
|
147 |
|
148 |
|
149 prettyDirTree :: Show a => DirTree a -> String |
|
150 prettyDirTree = undefined |
|
151 |
|
152 |
|
153 |
|
154 {---------------------------------------------------------------------} |
|
155 {- Aufgabe H7.3 -} |
|
156 |
|
157 {-WETT-} |
|
158 unscrambleWords :: [String] -> [String] -> [String] |
|
159 unscrambleWords = undefined |
|
160 {-TTEW-} |