diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-10-19 22:12:30 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-10-19 22:12:30 +0000 |
| commit | e86db4d8c8287790a90955fefec10b7a64988ff8 (patch) | |
| tree | b5c55391b69d76633c2f133fa67643a53efb87cc /examples/tutorial/semantics/AnswerBase.hs | |
| parent | 295c40fe3a96e88cfe500891cf2fdd27c87c241b (diff) | |
two versions of semantics (the Logic version incomplete)
Diffstat (limited to 'examples/tutorial/semantics/AnswerBase.hs')
| -rw-r--r-- | examples/tutorial/semantics/AnswerBase.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/tutorial/semantics/AnswerBase.hs b/examples/tutorial/semantics/AnswerBase.hs new file mode 100644 index 000000000..dbad37e5e --- /dev/null +++ b/examples/tutorial/semantics/AnswerBase.hs @@ -0,0 +1,44 @@ +module AnswerBase where + +import GSyntax + +-- interpretation of Base + +type Prop = Bool +type Exp = Int +domain = [0 .. 100] + +iS :: GS -> Prop +iS s = case s of + GPredAP np ap -> iNP np (iAP ap) + GConjS c s t -> iConj c (iS s) (iS t) + +iNP :: GNP -> (Exp -> Prop) -> Prop +iNP np p = case np of + GEvery cn -> all (\x -> not (iCN cn x) || p x) domain + GSome cn -> any (\x -> iCN cn x && p x) domain + GConjNP c np1 np2 -> iConj c (iNP np1 p) (iNP np2 p) + GUseInt (GInt i) -> p (fromInteger i) + +iAP :: GAP -> Exp -> Prop +iAP ap e = case ap of + GComplA2 a2 np -> iNP np (iA2 a2 e) + GConjAP c ap1 ap2 -> iConj c (iAP ap1 e) (iAP ap2 e) + GEven -> even e + GOdd -> not (even e) + +iCN :: GCN -> Exp -> Prop +iCN cn e = case cn of + GModCN ap cn0 -> (iCN cn0 e) && (iAP ap e) + GNumber -> True + +iConj :: GConj -> Prop -> Prop -> Prop +iConj c = case c of + GAnd -> (&&) + GOr -> (||) + +iA2 :: GA2 -> Exp -> Exp -> Prop +iA2 a2 e1 e2 = case a2 of + GGreater -> e1 > e1 + GSmaller -> e1 < e2 + GEqual -> e1 == e2 |
