1
- pub data Bool = False | True
1
+ (* This file is part of DBL, released under MIT license.
2
+ * See LICENSE for details.
3
+ *)
2
4
3
- pub data Option A = None | Some of A
5
+ import /Base/Types
6
+ import /Base/Operators
7
+ import /Base/Bool
8
+ import /Base/Int
9
+ import /Base/Char
10
+ import /Base/String
4
11
5
- pub data rec List A = [] | (::) of A, List A
6
-
7
- pub data Pair X Y = (,) of X, Y
8
-
9
- pub data Either X Y = Left of X | Right of Y
12
+ pub open Types
13
+ pub open Operators
10
14
11
15
pub let id x = x
12
16
@@ -17,107 +21,14 @@ pub let snd (_, y) = y
17
21
18
22
pub let not b = if b then False else True
19
23
20
- pub method toString = if self then "True" else "False"
21
-
22
- pub method fn (+) = add
23
- pub method fn (-) = sub
24
- pub method fn (%) = mod
25
- pub method fn (/) = div
26
- pub method fn ( * ) = mul
27
-
28
- pub method fn (==) = equal
29
- pub method fn (!=) = neq
30
- pub method fn (>) = gt
31
- pub method fn (>=) = ge
32
- pub method fn (<) = lt
33
- pub method fn (<=) = le
34
-
35
- pub method fn (&&&) = land
36
- pub method fn (^^^) = lxor
37
- pub method fn (|||) = lor
38
- pub method fn (<<) = shiftl
39
- pub method fn (>>) = shiftr
40
- pub method fn (>>>) = ashiftr
41
-
42
- pub method equal = (extern dbl_eqInt : Int -> Int -> Bool) self
43
- pub method neq = (extern dbl_neqInt : Int -> Int -> Bool) self
44
- pub method gt = (extern dbl_gtInt : Int -> Int -> Bool) self
45
- pub method lt = (extern dbl_ltInt : Int -> Int -> Bool) self
46
- pub method ge = (extern dbl_geInt : Int -> Int -> Bool) self
47
- pub method le = (extern dbl_leInt : Int -> Int -> Bool) self
48
-
49
- pub method toString = (extern dbl_intToString : Int -> String) self
50
-
51
- pub method add = (extern dbl_addInt : Int -> Int -> Int) self
52
- pub method sub = (extern dbl_subInt : Int -> Int -> Int) self
53
- pub method mul = (extern dbl_mulInt : Int -> Int -> Int) self
54
-
55
- pub method div {`re : {type X} -> Unit ->[|_] X} (n : Int) =
56
- if n.equal 0 then `re ()
57
- else (extern dbl_divInt : Int -> Int -> Int) self n
58
-
59
- pub method mod {`re : {type X} -> Unit ->[|_] X} (n : Int) =
60
- if n.equal 0 then `re ()
61
- else (extern dbl_modInt : Int -> Int -> Int) self n
62
-
63
- pub method land = (extern dbl_andInt : Int -> Int -> Int) self
64
- pub method lor = (extern dbl_orInt : Int -> Int -> Int) self
65
- pub method lxor = (extern dbl_xorInt : Int -> Int -> Int) self
66
-
67
- pub method shiftl = (extern dbl_lslInt : Int -> Int -> Int) self
68
- pub method shiftr = (extern dbl_lsrInt : Int -> Int -> Int) self
69
- pub method ashiftr = (extern dbl_asrInt : Int -> Int -> Int) self
70
-
71
- pub method add = (extern dbl_strCat : String -> String -> String) self
72
-
73
- pub method equal = (extern dbl_eqStr : String -> String -> Bool) self
74
- pub method neq = (extern dbl_neqStr : String -> String -> Bool) self
75
- pub method gt = (extern dbl_gtStr : String -> String -> Bool) self
76
- pub method lt = (extern dbl_ltStr : String -> String -> Bool) self
77
- pub method ge = (extern dbl_geStr : String -> String -> Bool) self
78
- pub method le = (extern dbl_leStr : String -> String -> Bool) self
79
-
80
- pub method length = (extern dbl_strLen : String -> Int) self
81
- pub method get {`re : {type X} -> Unit ->[|_] X, self : String} (n : Int) =
82
- if n >= 0 && n < self.length then
83
- (extern dbl_strGet : String -> Int -> Char) self n
84
- else `re ()
85
-
86
- pub method makeString {`re : {type X} -> Unit ->[|_] X, self : String}
87
- (n : Int) =
88
- if n >= 0 && n < 256 then
89
- (extern dbl_strMake : Int -> String) n
90
- else `re ()
91
-
92
- pub method toList {self : String} =
93
- let getChar = extern dbl_strGet : String -> Int -> Char in
94
- let rec iter (n : Int) acc =
95
- if n == 0 then
96
- acc
97
- else
98
- iter (n - 1) (getChar self (n - 1) :: acc)
99
- in iter self.length []
100
-
101
24
pub let charListToStr = (extern dbl_chrListToStr : List Char -> String)
102
25
103
- pub method code {self : Char} =
104
- extern dbl_chrCode : Char -> Int
105
-
106
26
pub let chr {`re : {type X} -> Unit ->[|_] X} (n : Int) =
107
27
if n >= 0 && n < 256 then
108
28
(extern dbl_intToChr : Int -> Char) n
109
29
else
110
30
`re ()
111
31
112
- pub method equal = (extern dbl_eqInt : Char -> Char -> Bool) self
113
- pub method neq = (extern dbl_neqInt : Char -> Char -> Bool) self
114
- pub method gt = (extern dbl_gtInt : Char -> Char -> Bool) self
115
- pub method lt = (extern dbl_ltInt : Char -> Char -> Bool) self
116
- pub method ge = (extern dbl_geInt : Char -> Char -> Bool) self
117
- pub method le = (extern dbl_leInt : Char -> Char -> Bool) self
118
-
119
- pub method toString = (extern dbl_chrToString : Char -> String) self
120
-
121
32
pub let printStrLn = extern dbl_printStrLn : String ->[IO] Unit
122
33
pub let printStr = extern dbl_printStr : String ->[IO] Unit
123
34
pub let printInt = extern dbl_printInt : Int ->[IO] Unit
0 commit comments