yukigo-haskell-parser 0.1.2 → 0.2.1

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.
Files changed (57) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +41 -7
  3. package/README.md +5 -10
  4. package/dist/index.js +21 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/parser/grammar.cjs +397 -0
  7. package/dist/parser/grammar.cjs.map +1 -0
  8. package/dist/parser/grammar.d.cts +38 -0
  9. package/dist/parser/lexer.d.ts +2 -1
  10. package/dist/parser/lexer.js +6 -1
  11. package/dist/parser/lexer.js.map +1 -1
  12. package/dist/prelude.js +279 -279
  13. package/dist/typechecker/DeclarationCollector.d.ts +2 -0
  14. package/dist/typechecker/DeclarationCollector.js +6 -5
  15. package/dist/typechecker/DeclarationCollector.js.map +1 -1
  16. package/dist/typechecker/TypeBuilder.js +9 -7
  17. package/dist/typechecker/TypeBuilder.js.map +1 -1
  18. package/dist/typechecker/checker.d.ts +9 -4
  19. package/dist/typechecker/checker.js +66 -94
  20. package/dist/typechecker/checker.js.map +1 -1
  21. package/dist/typechecker/core.js +8 -7
  22. package/dist/typechecker/core.js.map +1 -1
  23. package/dist/typechecker/inference.d.ts +4 -1
  24. package/dist/typechecker/inference.js +39 -19
  25. package/dist/typechecker/inference.js.map +1 -1
  26. package/dist/utils/helpers.d.ts +3 -0
  27. package/dist/utils/helpers.js +5 -0
  28. package/dist/utils/helpers.js.map +1 -1
  29. package/dist/utils/types.d.ts +12 -3
  30. package/dist/utils/types.js +34 -22
  31. package/dist/utils/types.js.map +1 -1
  32. package/package.json +9 -10
  33. package/src/index.ts +223 -192
  34. package/src/parser/{grammar.ts → grammar.cjs} +191 -223
  35. package/src/parser/grammar.d.ts +3 -0
  36. package/src/parser/grammar.ne +521 -518
  37. package/src/parser/lexer.ts +357 -353
  38. package/src/prelude.ts +281 -281
  39. package/src/typechecker/DeclarationCollector.ts +160 -157
  40. package/src/typechecker/TypeBuilder.ts +153 -150
  41. package/src/typechecker/checker.ts +487 -501
  42. package/src/typechecker/core.ts +195 -192
  43. package/src/typechecker/inference.ts +1442 -1421
  44. package/src/utils/helpers.ts +34 -29
  45. package/src/utils/types.ts +75 -63
  46. package/tests/hspec.spec.ts +95 -92
  47. package/tests/lexer.spec.ts +175 -175
  48. package/tests/parser.spec.ts +838 -829
  49. package/tests/prelude.spec.ts +17 -17
  50. package/tests/typechecker.spec.ts +326 -327
  51. package/tsconfig.build.json +16 -0
  52. package/tsconfig.build.tsbuildinfo +1 -0
  53. package/tsconfig.json +29 -26
  54. package/tsconfig.tsbuildinfo +1 -1
  55. package/dist/parser/grammar.d.ts +0 -28
  56. package/dist/parser/grammar.js +0 -393
  57. package/dist/parser/grammar.js.map +0 -1
package/src/prelude.ts CHANGED
@@ -1,282 +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
- 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) ++ "]")
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
282
  `