-
Notifications
You must be signed in to change notification settings - Fork 0
/
FSynF.hs
executable file
·144 lines (117 loc) · 4.02 KB
/
FSynF.hs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
module FSynF where
import Data.List
data Column = A' | B' | C' | D' | E'
| F' | G' | H' | I' | J'
deriving (Eq,Ord,Show,Enum)
type Row = Int
type Attack = (Column,Row)
data Ship = Battleship | Frigate | Submarine | Destroyer
deriving Show
data Reaction = Missed | Hit Ship | Sunk Ship | LostBattle
deriving Show
type Turn = (Attack,Reaction)
data Colour = Red | Yellow | Blue | Green | Orange
deriving (Eq,Show,Bounded,Enum)
data Answer = Black | White deriving (Eq,Show)
type Pattern = [Colour]
type Feedback = [Answer]
data Sent = Sent NP VP deriving Show
data NP = SnowWhite | Alice | Dorothy | Goldilocks
| LittleMook | Atreyu | Everyone | Someone
| NP1 DET CN | NP2 DET RCN
deriving Show
data DET = The | Every | Some | No | Most
deriving Show
data CN = Girl | Boy | Princess | Dwarf | Giant
| Wizard | Sword | Dagger
deriving Show
data ADJ = Fake deriving Show
data RCN = RCN1 CN That VP | RCN2 CN That NP TV
| RCN3 ADJ CN
deriving Show
data That = That deriving Show
data VP = Laughed | Cheered | Shuddered
| VP1 TV NP | VP2 DV NP NP
| VP3 AV To INF
deriving Show
data TV = Loved | Admired | Helped
| Defeated | Caught
deriving Show
data DV = Gave deriving Show
data AV = Hoped | Wanted deriving Show
data INF = Laugh | Sheer | Shudder | INF TINF NP deriving Show
data TINF = Love | Admire | Help | Defeat | Catch
deriving Show
data To = To deriving Show
data Form = P String | Ng Form | Cnj [Form] | Dsj [Form]
deriving Eq
instance Show Form where
show (P name) = name
show (Ng f) = '-': show f
show (Cnj fs) = '&': show fs
show (Dsj fs) = 'v': show fs
form1, form2 :: Form
form1 = Cnj [P "p", Ng (P "p")]
form2 = Dsj [P "p1", P "p2", P "p3", P "p4"]
type Name = String
type Index = [Int]
data Variable = Variable Name Index deriving (Eq,Ord)
instance Show Variable where
show (Variable name []) = name
show (Variable name [i]) = name ++ show i
show (Variable name is ) = name ++ showInts is
where showInts [] = ""
showInts [i] = show i
showInts (i:is) = show i ++ "_" ++ showInts is
x, y, z :: Variable
x = Variable "x" []
y = Variable "y" []
z = Variable "z" []
data Formula a = Atom String [a]
| Eq a a
| Neg (Formula a)
| Impl (Formula a) (Formula a)
| Equi (Formula a) (Formula a)
| Conj [Formula a]
| Disj [Formula a]
| Forall Variable (Formula a)
| Exists Variable (Formula a)
deriving Eq
instance Show a => Show (Formula a) where
show (Atom s []) = s
show (Atom s xs) = s ++ show xs
show (Eq t1 t2) = show t1 ++ "==" ++ show t2
show (Neg form) = '~' : (show form)
show (Impl f1 f2) = "(" ++ show f1 ++ "==>"
++ show f2 ++ ")"
show (Equi f1 f2) = "(" ++ show f1 ++ "<=>"
++ show f2 ++ ")"
show (Conj []) = "true"
show (Conj fs) = "conj" ++ show fs
show (Disj []) = "false"
show (Disj fs) = "disj" ++ show fs
show (Forall v f) = "A " ++ show v ++ (' ' : show f)
show (Exists v f) = "E " ++ show v ++ (' ' : show f)
formula0 = Atom "R" [x,y]
formula1 = Forall x (Atom "R" [x,x])
formula2 = Forall x
(Forall y
(Impl (Atom "R" [x,y]) (Atom "R" [y,x])))
data Term = Var Variable | Struct String [Term]
deriving (Eq,Ord)
instance Show Term where
show (Var v) = show v
show (Struct s []) = s
show (Struct s ts) = s ++ show ts
tx, ty, tz :: Term
tx = Var x
ty = Var y
tz = Var z
isVar :: Term -> Bool
isVar (Var _) = True
isVar _ = False
varsInTerm :: Term -> [Variable]
varsInTerm (Var v) = [v]
varsInTerm (Struct s ts) = varsInTerms ts
varsInTerms :: [Term] -> [Variable]
varsInTerms = nub . concat . map varsInTerm