yukigo-haskell-parser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +6 -0
- package/README.md +10 -10
- package/dist/index.d.ts +13 -2
- package/dist/index.js +112 -32
- package/dist/index.js.map +1 -1
- package/dist/parser/grammar.js +220 -231
- package/dist/parser/grammar.js.map +1 -1
- package/dist/parser/lexer.d.ts +70 -15
- package/dist/parser/lexer.js +259 -50
- package/dist/parser/lexer.js.map +1 -1
- package/dist/prelude.d.ts +1 -1
- package/dist/prelude.js +280 -204
- package/dist/prelude.js.map +1 -1
- package/dist/typechecker/DeclarationCollector.d.ts +6 -1
- package/dist/typechecker/DeclarationCollector.js +39 -0
- package/dist/typechecker/DeclarationCollector.js.map +1 -1
- package/dist/typechecker/TypeBuilder.d.ts +1 -1
- package/dist/typechecker/TypeBuilder.js +6 -2
- package/dist/typechecker/TypeBuilder.js.map +1 -1
- package/dist/typechecker/checker.d.ts +15 -4
- package/dist/typechecker/checker.js +108 -25
- package/dist/typechecker/checker.js.map +1 -1
- package/dist/typechecker/core.d.ts +4 -0
- package/dist/typechecker/core.js +45 -19
- package/dist/typechecker/core.js.map +1 -1
- package/dist/typechecker/inference.d.ts +5 -1
- package/dist/typechecker/inference.js +95 -21
- package/dist/typechecker/inference.js.map +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.js +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/types.d.ts +1 -1
- package/dist/utils/types.js +7 -0
- package/dist/utils/types.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +192 -55
- package/src/parser/grammar.ne +519 -463
- package/src/parser/grammar.ts +230 -239
- package/src/parser/lexer.ts +353 -77
- package/src/prelude.ts +282 -206
- package/src/typechecker/DeclarationCollector.ts +157 -104
- package/src/typechecker/TypeBuilder.ts +150 -148
- package/src/typechecker/checker.ts +501 -395
- package/src/typechecker/core.ts +192 -162
- package/src/typechecker/inference.ts +1421 -1327
- package/src/utils/helpers.ts +29 -29
- package/src/utils/types.ts +63 -56
- package/tests/hspec.spec.ts +92 -0
- package/tests/lexer.spec.ts +175 -0
- package/tests/parser.spec.ts +829 -823
- package/tests/prelude.spec.ts +17 -22
- package/tests/typechecker.spec.ts +327 -310
- package/tsconfig.json +26 -17
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/parser/layoutPreprocessor.d.ts +0 -1
- package/dist/parser/layoutPreprocessor.js +0 -22
- package/dist/parser/layoutPreprocessor.js.map +0 -1
- package/dist/parser/preprocessor.d.ts +0 -28
- package/dist/parser/preprocessor.js +0 -453
- package/dist/parser/preprocessor.js.map +0 -1
- package/src/parser/layoutPreprocessor.ts +0 -21
- package/src/parser/preprocessor.ne +0 -375
- package/src/parser/preprocessor.ts +0 -502
- package/tests/preprocessor.spec.ts +0 -69
package/src/prelude.ts
CHANGED
|
@@ -1,206 +1,282 @@
|
|
|
1
|
-
import { YukigoHaskellParser } from "./index.js"
|
|
2
|
-
|
|
3
|
-
export const preludeCode = `data Ordering = LT | EQ | GT
|
|
4
|
-
data Maybe a = Nothing | Just a
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
1
|
+
import { YukigoHaskellParser } from "./index.js"
|
|
2
|
+
|
|
3
|
+
export const preludeCode = `data Ordering = LT | EQ | GT
|
|
4
|
+
data Maybe a = Nothing | Just a
|
|
5
|
+
id :: a -> a
|
|
6
|
+
id x = x
|
|
7
|
+
const :: a -> b -> a
|
|
8
|
+
const x _ = x
|
|
9
|
+
(,) :: a -> b -> (a, b)
|
|
10
|
+
(,) x y = (x, y)
|
|
11
|
+
($) :: (a -> b) -> a -> b
|
|
12
|
+
($) f x = f x
|
|
13
|
+
($!) :: (a -> b) -> a -> b
|
|
14
|
+
($!) f x = f x
|
|
15
|
+
(.) :: (b -> c) -> (a -> b) -> a -> c
|
|
16
|
+
(.) f g a = (\\x -> f (g x)) a
|
|
17
|
+
(:) :: a -> [a] -> [a]
|
|
18
|
+
(:) x xs = x : xs
|
|
19
|
+
(++) :: [a] -> [a] -> [a]
|
|
20
|
+
(++) [] ys = ys
|
|
21
|
+
(++) (x:xs) ys = x : (xs ++ ys)
|
|
22
|
+
(&&) :: Bool -> Bool -> Bool
|
|
23
|
+
(||) :: Bool -> Bool -> Bool
|
|
24
|
+
(&&) x y = x && y
|
|
25
|
+
(||) x y = x || y
|
|
26
|
+
(==) :: (Ord a) => a -> a -> Boolean
|
|
27
|
+
(==) x y = x == y
|
|
28
|
+
(/=) :: (Ord a) => a -> a -> Boolean
|
|
29
|
+
(/=) x y = x /= y
|
|
30
|
+
(<) :: (Ord a) => a -> a -> Boolean
|
|
31
|
+
(<) x y = x < y
|
|
32
|
+
(>) :: (Ord a) => a -> a -> Boolean
|
|
33
|
+
(>) x y = x > y
|
|
34
|
+
(<=) :: (Ord a) => a -> a -> Boolean
|
|
35
|
+
(<=) x y = x <= y
|
|
36
|
+
(>=) :: (Ord a) => a -> a -> Boolean
|
|
37
|
+
(>=) x y = x >= y
|
|
38
|
+
(+) :: Num a => a -> a -> a
|
|
39
|
+
(-) :: Num a => a -> a -> a
|
|
40
|
+
(+) x y = x + y
|
|
41
|
+
(-) x y = x - y
|
|
42
|
+
(**) :: (Floating a) => a -> a -> a
|
|
43
|
+
(**) x y = x ** y
|
|
44
|
+
(^) :: (Num a, Integral b) => a -> b -> a
|
|
45
|
+
(^) x y = x ^ y
|
|
46
|
+
(^^) :: (Fractional a, Integral b) => a -> b -> a
|
|
47
|
+
(^^) x y = x ^^ y
|
|
48
|
+
(*) :: (Num a) => a -> a -> a
|
|
49
|
+
(*) x y = x * y
|
|
50
|
+
(/) :: Fractional a => a -> a -> a
|
|
51
|
+
(/) _ 0 = error "Prelude./: divide by zero"
|
|
52
|
+
(/) x y = x / y
|
|
53
|
+
(!!) :: [a] -> Int -> a
|
|
54
|
+
(!!) xs n | n < 0 = error "Prelude.!!: negative index"
|
|
55
|
+
(!!) [] _ = error "Prelude.!!: index too large"
|
|
56
|
+
(!!) (x:_) 0 = x
|
|
57
|
+
(!!) (_:xs) n = xs !! (n - 1)
|
|
58
|
+
not :: Bool -> Bool
|
|
59
|
+
not True = False
|
|
60
|
+
not False = True
|
|
61
|
+
quot :: Integral a => a -> a -> a
|
|
62
|
+
quot _ 0 = error "divide by zero"
|
|
63
|
+
quot 0 _ = 0
|
|
64
|
+
quot a b = let { absA = abs a; absB = abs b; result = quotPositive absA absB } in if (a < 0) == (b < 0) then result else -result
|
|
65
|
+
rem :: Integral a => a -> a -> a
|
|
66
|
+
rem _ 0 = error "divide by zero"
|
|
67
|
+
rem 0 _ = 0
|
|
68
|
+
rem a b = let { absA = abs a; absB = abs b; remainder = remPositive absA absB } in if a < 0 then -remainder else remainder
|
|
69
|
+
quotPositive :: Integral a => a -> a -> a
|
|
70
|
+
quotPositive n d | n < d = 0 | otherwise = 1 + quotPositive (n - d) d
|
|
71
|
+
remPositive :: Integral a => a -> a -> a
|
|
72
|
+
remPositive n d | n < d = n | otherwise = remPositive (n - d) d
|
|
73
|
+
div :: Integral a => a -> a -> a
|
|
74
|
+
div _ 0 = error "divide by zero"
|
|
75
|
+
div 0 _ = 0
|
|
76
|
+
div a b = let { q = quot a b; r = rem a b } in if r == 0 || (a < 0) == (b < 0) then q else q - 1
|
|
77
|
+
mod :: Integral a => a -> a -> a
|
|
78
|
+
mod _ 0 = error "divide by zero"
|
|
79
|
+
mod 0 _ = 0
|
|
80
|
+
mod a b = a - (div a b) * b
|
|
81
|
+
signum :: (Num a) => a -> a
|
|
82
|
+
signum x | x == 0 = 0 | x > 0 = 1 | otherwise = -1
|
|
83
|
+
abs :: (Num a) => a -> a
|
|
84
|
+
abs n = if n < 0 then -n else n
|
|
85
|
+
succ :: (Num a) => a -> a
|
|
86
|
+
succ x = x + 1
|
|
87
|
+
pred :: (Num a) => a -> a
|
|
88
|
+
pred x = x - 1
|
|
89
|
+
sqrt :: (Num a) => a -> a
|
|
90
|
+
sqrt x = x ** 0.5
|
|
91
|
+
max :: Ord a => a -> a -> a
|
|
92
|
+
max x y = if x <= y then y else x
|
|
93
|
+
min :: Ord a => a -> a -> a
|
|
94
|
+
min x y = if x <= y then x else y
|
|
95
|
+
even :: (Integral a) => a -> Bool
|
|
96
|
+
odd :: (Integral a) => a -> Bool
|
|
97
|
+
even n = n \`rem\` 2 == 0
|
|
98
|
+
odd n = (not . even) n
|
|
99
|
+
length :: [a] -> Int
|
|
100
|
+
length [] = 0
|
|
101
|
+
length (_:l) = 1 + length l
|
|
102
|
+
genericLength :: (Integral a) => [b] -> a
|
|
103
|
+
genericLength [] = 0
|
|
104
|
+
genericLength (x:xs) = 1 + genericLength xs
|
|
105
|
+
null :: [a] -> Bool
|
|
106
|
+
null [] = True
|
|
107
|
+
null (_:_) = False
|
|
108
|
+
union :: (Eq a) => [a] -> [a] -> [a]
|
|
109
|
+
union xs ys = unionBy (==) xs ys
|
|
110
|
+
deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
|
|
111
|
+
deleteBy eq x [] = []
|
|
112
|
+
deleteBy eq x (y:ys) = if x \`eq\` y then ys else y : deleteBy eq x ys
|
|
113
|
+
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
|
|
114
|
+
deleteFirstsBy eq xs ys = foldl (flip (deleteBy eq)) xs ys
|
|
115
|
+
nubBy :: (a -> a -> Bool) -> [a] -> [a]
|
|
116
|
+
nubBy eq [] = []
|
|
117
|
+
nubBy eq (x:xs) = x : nubBy eq (filter (\\y -> not (eq x y)) xs)
|
|
118
|
+
unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
|
|
119
|
+
unionBy eq xs ys = xs ++ deleteFirstsBy eq (nubBy eq ys) xs
|
|
120
|
+
intersect :: (Eq a) => [a] -> [a] -> [a]
|
|
121
|
+
intersect xs ys = intersectBy (==) xs ys
|
|
122
|
+
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
|
|
123
|
+
intersectBy eq xs ys = [x | x <- xs, any (eq x) ys]
|
|
124
|
+
elem :: (Eq a) => a -> [a] -> Bool
|
|
125
|
+
notElem :: (Eq a) => a -> [a] -> Bool
|
|
126
|
+
elem x xs = any (\\y -> y == x) xs
|
|
127
|
+
notElem x xs = all (\\y -> y /= x) xs
|
|
128
|
+
maximum :: (Ord a) => [a] -> a
|
|
129
|
+
minimum :: (Ord a) => [a] -> a
|
|
130
|
+
maximum [] = error "Prelude.maximum: empty list"
|
|
131
|
+
maximum xs = foldl1 max xs
|
|
132
|
+
minimum [] = error "Prelude.minimum: empty list"
|
|
133
|
+
minimum xs = foldl1 min xs
|
|
134
|
+
sum :: (Num a) => [a] -> a
|
|
135
|
+
product :: (Num a) => [a] -> a
|
|
136
|
+
sum xs = foldl (+) 0 xs
|
|
137
|
+
product xs = foldl (*) 1 xs
|
|
138
|
+
concat :: [[a]] -> [a]
|
|
139
|
+
concat xss = foldr (++) [] xss
|
|
140
|
+
concatMap :: (a -> [b]) -> [a] -> [b]
|
|
141
|
+
concatMap f xs = (concat . map) f xs
|
|
142
|
+
take :: Int -> [a] -> [a]
|
|
143
|
+
take n _ | n <= 0 = []
|
|
144
|
+
take _ [] = []
|
|
145
|
+
take n (x:xs) = x : take (n - 1) xs
|
|
146
|
+
drop :: Int -> [a] -> [a]
|
|
147
|
+
drop n xs | n <= 0 = xs
|
|
148
|
+
drop _ [] = []
|
|
149
|
+
drop n (_:xs) = drop (n - 1) xs
|
|
150
|
+
head :: [a] -> a
|
|
151
|
+
head (x:_) = x
|
|
152
|
+
head [] = error "Prelude.head: empty list"
|
|
153
|
+
tail :: [a] -> [a]
|
|
154
|
+
tail (_:xs) = xs
|
|
155
|
+
tail [] = error "Prelude.tail: empty list"
|
|
156
|
+
last :: [a] -> a
|
|
157
|
+
last [x] = x
|
|
158
|
+
last (_:xs) = last xs
|
|
159
|
+
last [] = error "Prelude.last: empty list"
|
|
160
|
+
init :: [a] -> [a]
|
|
161
|
+
init [x] = []
|
|
162
|
+
init (x:xs) = x : init xs
|
|
163
|
+
init [] = error "Prelude.init: empty list"
|
|
164
|
+
zip :: [a] -> [b] -> [(a, b)]
|
|
165
|
+
zip xs ys = zipWith (,) xs ys
|
|
166
|
+
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
|
167
|
+
zipWith z (a:as) (b:bs) = z a b : zipWith z as bs
|
|
168
|
+
zipWith _ _ _ = []
|
|
169
|
+
reverse :: [a] -> [a]
|
|
170
|
+
reverse xs = foldl (flip (:)) [] xs
|
|
171
|
+
filter :: (a -> Bool) -> [a] -> [a]
|
|
172
|
+
filter p [] = []
|
|
173
|
+
filter p (x:xs) | p x = x : filter p xs | otherwise = filter p xs
|
|
174
|
+
map :: (a -> b) -> [a] -> [b]
|
|
175
|
+
map f [] = []
|
|
176
|
+
map f (x:xs) = f x : map f xs
|
|
177
|
+
any :: (a -> Bool) -> [a] -> Bool
|
|
178
|
+
any f [] = False
|
|
179
|
+
any f (x:xs) = f x || any f xs
|
|
180
|
+
all :: (a -> Bool) -> [a] -> Bool
|
|
181
|
+
all f [] = True
|
|
182
|
+
all f (x:xs) = f x && all f xs
|
|
183
|
+
foldl :: (a -> b -> a) -> a -> [b] -> a
|
|
184
|
+
foldl f z [] = z
|
|
185
|
+
foldl f z (x:xs) = foldl f (f z x) xs
|
|
186
|
+
foldl1 :: (a -> a -> a) -> [a] -> a
|
|
187
|
+
foldl1 f (x:xs) = foldl f x xs
|
|
188
|
+
foldl1 _ [] = error "Prelude.foldl1: empty list"
|
|
189
|
+
foldr :: (a -> b -> b) -> b -> [a] -> b
|
|
190
|
+
foldr f z [] = z
|
|
191
|
+
foldr f z (x:xs) = f x (foldr f z xs)
|
|
192
|
+
foldr1 :: (a -> a -> a) -> [a] -> a
|
|
193
|
+
foldr1 f [x] = x
|
|
194
|
+
foldr1 f (x:xs) = f x (foldr1 f xs)
|
|
195
|
+
foldr1 _ [] = error "Prelude.foldr1: empty list"
|
|
196
|
+
find :: Ord a => (a -> Bool) -> [a] -> Maybe a
|
|
197
|
+
find _ [] = Nothing
|
|
198
|
+
find f (x:xs) | f x = Just x | otherwise = find f xs
|
|
199
|
+
sort :: (Ord a) => [a] -> [a]
|
|
200
|
+
sort xs = sortBy compare xs
|
|
201
|
+
sortBy :: (a -> a -> Ordering) -> [a] -> [a]
|
|
202
|
+
sortBy cmp xs = foldr (insertBy cmp) [] xs
|
|
203
|
+
compare :: Ord a => a -> a -> Ordering
|
|
204
|
+
compare x y | x == y = EQ | x <= y = LT | otherwise = GT
|
|
205
|
+
insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
|
|
206
|
+
insertBy cmp x [] = [x]
|
|
207
|
+
insertBy cmp x ys@(y:ys') = case cmp x y of { GT -> y : insertBy cmp x ys'; _ -> x : ys }
|
|
208
|
+
flip :: (a -> b -> c) -> b -> a -> c
|
|
209
|
+
flip f x y = f y x
|
|
210
|
+
repeat :: a -> [a]
|
|
211
|
+
repeat x = x : (repeat x)
|
|
212
|
+
iterate :: (a -> a) -> a -> [a]
|
|
213
|
+
iterate f x = x : iterate f (f x)
|
|
214
|
+
replicate :: Int -> a -> [a]
|
|
215
|
+
replicate n x = take n (repeat x)
|
|
216
|
+
cycle :: [a] -> [a]
|
|
217
|
+
cycle [] = error "Prelude.cycle: empty list"
|
|
218
|
+
cycle xs = xs ++ (cycle xs)
|
|
219
|
+
fst :: (a,b) -> a
|
|
220
|
+
fst (x,_) = x
|
|
221
|
+
snd :: (a,b) -> b
|
|
222
|
+
snd (_,y) = y
|
|
223
|
+
between :: Ord a => a -> a -> a -> Bool
|
|
224
|
+
between m n p | n >= m && n <= p = True | otherwise = False
|
|
225
|
+
truncate :: (Num a, Integral b) => a -> b
|
|
226
|
+
truncate x = quot x 1
|
|
227
|
+
floor :: (Num a, Integral b) => a -> b
|
|
228
|
+
floor x = div x 1
|
|
229
|
+
negate :: Num a => a -> a
|
|
230
|
+
negate n = 0 - n
|
|
231
|
+
ceiling :: (Num a, Integral b) => a -> b
|
|
232
|
+
ceiling x = negate (floor (negate x))
|
|
233
|
+
round :: (Num a, Integral b) => a -> b
|
|
234
|
+
round x | r < 0.5 = n | r > 0.5 = n + 1 | even n = n | otherwise = n + 1 where { n = floor x; r = x - n }
|
|
235
|
+
dropWhile :: (a -> Bool) -> [a] -> [a]
|
|
236
|
+
dropWhile _ [] = []
|
|
237
|
+
dropWhile p xs@(x:xs') | p x = dropWhile p xs' | otherwise = xs
|
|
238
|
+
break :: (a -> Bool) -> [a] -> ([a], [a])
|
|
239
|
+
break _ [] = ([], [])
|
|
240
|
+
break p (x:xs) | p x = ([], x:xs) | otherwise = (x : fst (break p xs), snd (break p xs))
|
|
241
|
+
words :: String -> [String]
|
|
242
|
+
words s = let { sTrim = dropWhile (\\c -> c == ' ') s } in if null sTrim then [] else fst (break (\\c -> c == ' ') sTrim) : words (snd (break (\\c -> c == ' ') sTrim))
|
|
243
|
+
intersperse :: a -> [a] -> [a]
|
|
244
|
+
intersperse _ [] = []
|
|
245
|
+
intersperse _ [x] = [x]
|
|
246
|
+
intersperse sep (x:xs) = x : sep : intersperse sep xs
|
|
247
|
+
intercalate :: [a] -> [[a]] -> [a]
|
|
248
|
+
intercalate xs xss = concat (intersperse xs xss)
|
|
249
|
+
fromIntegral :: (Integral a, Num b) => a -> b
|
|
250
|
+
fromIntegral x = x
|
|
251
|
+
|
|
252
|
+
anyException = ""
|
|
253
|
+
evaluate x = x
|
|
254
|
+
|
|
255
|
+
class Show a where
|
|
256
|
+
show :: a -> String
|
|
257
|
+
|
|
258
|
+
instance Show Int where
|
|
259
|
+
show x = primShow x
|
|
260
|
+
|
|
261
|
+
instance Show Bool where
|
|
262
|
+
show True = "True"
|
|
263
|
+
show False = "False"
|
|
264
|
+
|
|
265
|
+
instance Show Ordering where
|
|
266
|
+
show LT = "LT"
|
|
267
|
+
show EQ = "EQ"
|
|
268
|
+
show GT = "GT"
|
|
269
|
+
|
|
270
|
+
instance Show (Maybe a) where
|
|
271
|
+
show Nothing = "Nothing"
|
|
272
|
+
show (Just x) = "Just " ++ show x
|
|
273
|
+
|
|
274
|
+
instance Show Char where
|
|
275
|
+
show c = '\\'' : c : '\\'' : []
|
|
276
|
+
|
|
277
|
+
instance Show String where
|
|
278
|
+
show s = primShowString s
|
|
279
|
+
|
|
280
|
+
instance Show [a] where
|
|
281
|
+
show xs = '[' : (intercalate "," (map show xs) ++ "]")
|
|
282
|
+
`
|