blob: 17859aefcd4bbfd377a2990099b853425eba28c4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
implementation module MatchStrings
import StdEnv
head :: String -> Char
head "" = abort "head uitgevoerd op lege string"
head s = s.[0]
tail :: String -> String
tail "" = abort "tail uitgevoerd op lege string"
tail s = s % (1, size s - 1)
is_gelijk :: String String -> Bool
is_gelijk "" "" = True
is_gelijk a "" = False
is_gelijk "" b = False
is_gelijk a b = (head a == head b) && (is_gelijk (tail a) (tail b))
is_deelstring :: String String -> Bool
is_deelstring "" b = True
is_deelstring a "" = False
is_deelstring a b = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b)
is_deel :: String String -> Bool
is_deel "" b = True
is_deel a "" = False
is_deel a b = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)
is_match :: String String -> Bool
is_match "" "" = True
is_match "" b = False
is_match "*" "" = True
is_match a "" = False
is_match a b = (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b)
//Start = (head pink_floyd, tail pink_floyd)
//Start = is_gelijk "" " "
//Start = is_deelstring "there" pink_floyd
//Start = is_deelstring "there" marillion
//Start = is_deel "there" marillion
//Start = is_deel "she and her" pink_floyd
//Start = is_deel radiohead pink_floyd
//Start = is_match "*.here*.here*." pink_floyd
//Start = is_match ".here.here." pink_floyd
pink_floyd = "Is there anybody in there?"
marillion = "Just for the record"
radiohead = "There there"
|