-
Notifications
You must be signed in to change notification settings - Fork 1
/
oper.sml
61 lines (53 loc) · 1.41 KB
/
oper.sml
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
(* oper.sml
*
* (Source-level) arithmetic- and comparison operators for MLPolyR.
*
* Copyright (c) 2005 by Matthias Blume ([email protected])
*)
structure Oper = struct
datatype cmpop =
EQ
| LTEQ
| LT
| GTEQ
| GT
| NEQ
datatype arithop =
PLUS
| MINUS
| TIMES
| DIV
| MOD
fun purearith PLUS = true
| purearith MINUS = true
| purearith TIMES = true
| purearith DIV = false
| purearith MOD = false
fun commutative PLUS = true
| commutative MINUS = false
| commutative TIMES = true
| commutative DIV = false
| commutative MOD = false
fun doarith (PLUS, x: LiteralData.integer, y) = x + y
| doarith (MINUS, x, y) = x - y
| doarith (TIMES, x, y) = (x div 2) * (y div 2) * 2
| doarith (DIV, x, y) = ((x div 2) div (y div 2)) * 2
| doarith (MOD, x, y) = x mod y
fun astring PLUS = "+"
| astring MINUS = "-"
| astring TIMES = "*"
| astring DIV = "/"
| astring MOD = "%"
fun docmp (EQ, x: LiteralData.integer, y) = x = y
| docmp (LTEQ, x, y) = x <= y
| docmp (LT, x, y) = x < y
| docmp (GTEQ, x, y) = x >= y
| docmp (GT, x, y) = x > y
| docmp (NEQ, x, y) = x <> y
fun cstring EQ = "=="
| cstring LTEQ = "<="
| cstring LT = "<"
| cstring GTEQ = ">="
| cstring GT = ">"
| cstring NEQ = "<>"
end