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.
Files changed (65) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +6 -0
  3. package/README.md +10 -10
  4. package/dist/index.d.ts +13 -2
  5. package/dist/index.js +112 -32
  6. package/dist/index.js.map +1 -1
  7. package/dist/parser/grammar.js +220 -231
  8. package/dist/parser/grammar.js.map +1 -1
  9. package/dist/parser/lexer.d.ts +70 -15
  10. package/dist/parser/lexer.js +259 -50
  11. package/dist/parser/lexer.js.map +1 -1
  12. package/dist/prelude.d.ts +1 -1
  13. package/dist/prelude.js +280 -204
  14. package/dist/prelude.js.map +1 -1
  15. package/dist/typechecker/DeclarationCollector.d.ts +6 -1
  16. package/dist/typechecker/DeclarationCollector.js +39 -0
  17. package/dist/typechecker/DeclarationCollector.js.map +1 -1
  18. package/dist/typechecker/TypeBuilder.d.ts +1 -1
  19. package/dist/typechecker/TypeBuilder.js +6 -2
  20. package/dist/typechecker/TypeBuilder.js.map +1 -1
  21. package/dist/typechecker/checker.d.ts +15 -4
  22. package/dist/typechecker/checker.js +108 -25
  23. package/dist/typechecker/checker.js.map +1 -1
  24. package/dist/typechecker/core.d.ts +4 -0
  25. package/dist/typechecker/core.js +45 -19
  26. package/dist/typechecker/core.js.map +1 -1
  27. package/dist/typechecker/inference.d.ts +5 -1
  28. package/dist/typechecker/inference.js +95 -21
  29. package/dist/typechecker/inference.js.map +1 -1
  30. package/dist/utils/helpers.d.ts +1 -1
  31. package/dist/utils/helpers.js +1 -1
  32. package/dist/utils/helpers.js.map +1 -1
  33. package/dist/utils/types.d.ts +1 -1
  34. package/dist/utils/types.js +7 -0
  35. package/dist/utils/types.js.map +1 -1
  36. package/package.json +3 -3
  37. package/src/index.ts +192 -55
  38. package/src/parser/grammar.ne +519 -463
  39. package/src/parser/grammar.ts +230 -239
  40. package/src/parser/lexer.ts +353 -77
  41. package/src/prelude.ts +282 -206
  42. package/src/typechecker/DeclarationCollector.ts +157 -104
  43. package/src/typechecker/TypeBuilder.ts +150 -148
  44. package/src/typechecker/checker.ts +501 -395
  45. package/src/typechecker/core.ts +192 -162
  46. package/src/typechecker/inference.ts +1421 -1327
  47. package/src/utils/helpers.ts +29 -29
  48. package/src/utils/types.ts +63 -56
  49. package/tests/hspec.spec.ts +92 -0
  50. package/tests/lexer.spec.ts +175 -0
  51. package/tests/parser.spec.ts +829 -823
  52. package/tests/prelude.spec.ts +17 -22
  53. package/tests/typechecker.spec.ts +327 -310
  54. package/tsconfig.json +26 -17
  55. package/tsconfig.tsbuildinfo +1 -0
  56. package/dist/parser/layoutPreprocessor.d.ts +0 -1
  57. package/dist/parser/layoutPreprocessor.js +0 -22
  58. package/dist/parser/layoutPreprocessor.js.map +0 -1
  59. package/dist/parser/preprocessor.d.ts +0 -28
  60. package/dist/parser/preprocessor.js +0 -453
  61. package/dist/parser/preprocessor.js.map +0 -1
  62. package/src/parser/layoutPreprocessor.ts +0 -21
  63. package/src/parser/preprocessor.ne +0 -375
  64. package/src/parser/preprocessor.ts +0 -502
  65. 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
- (,) :: a -> b -> (a, b)
6
- (,) x y = (x, y)
7
- ($) :: (a -> b) -> a -> b
8
- ($) f x = f x
9
- (.) :: (b -> c) -> (a -> b) -> a -> c
10
- (.) f g a = (\\x -> f (g x)) a
11
- (:) :: a -> [a] -> [a]
12
- (:) x xs = x : xs
13
- (++) :: [a] -> [a] -> [a]
14
- (++) [] ys = ys
15
- (++) (x:xs) ys = x : (xs ++ ys)
16
- (&&) :: (Eq a) => a -> a -> Boolean
17
- (||) :: (Eq a) => a -> a -> Boolean
18
- (&&) x y = x && y
19
- (||) x y = x || y
20
- (==) :: (Ord a) => a -> a -> Boolean
21
- (/=) :: (Ord a) => a -> a -> Boolean
22
- (<) :: (Ord a) => a -> a -> Boolean
23
- (>) :: (Ord a) => a -> a -> Boolean
24
- (<=) :: (Ord a) => a -> a -> Boolean
25
- (>=) :: (Ord a) => a -> a -> Boolean
26
- (==) x y = x == y
27
- (/=) x y = x /= y
28
- (<) x y = x < y
29
- (>) x y = x > y
30
- (<=) x y = x <= y
31
- (>=) x y = x >= y
32
- (+) :: Num a => a -> a -> a
33
- (-) :: Num a => a -> a -> a
34
- (+) x y = x + y
35
- (-) x y = x - y
36
- (**) :: (Floating a) => a -> a -> a
37
- (**) x y = x ** y
38
- (^) :: (Num a, Integral b) => a -> b -> a
39
- (^) x y = x ^ y
40
- (^^) :: (Fractional a, Integral b) => a -> b -> a
41
- (^^) x y = x ^^ y
42
- (*) :: (Num a) => a -> a -> a
43
- (*) x y = x * y
44
- (/) :: Fractional a => a -> a -> a
45
- (/) _ 0 = error "Prelude./: divide by zero"
46
- (/) x y = x / y
47
- (!!) :: [a] -> Int -> a
48
- (!!) xs n | n < 0 = error "Prelude.!!: negative index"
49
- (!!) [] _ = error "Prelude.!!: index too large"
50
- (!!) (x:_) 0 = x
51
- (!!) (_:xs) n = xs !! (n - 1)
52
- not :: Bool -> Bool
53
- not True = False
54
- not False = True
55
- quot :: Integral a => a -> a -> a
56
- quot _ 0 = error "divide by zero"
57
- quot 0 _ = 0
58
- quot a b = let { absA = abs a; absB = abs b; result = quotPositive absA absB } in if (a < 0) == (b < 0) then result else -result
59
- rem :: Integral a => a -> a -> a
60
- rem _ 0 = error "divide by zero"
61
- rem 0 _ = 0
62
- rem a b = let { absA = abs a; absB = abs b; remainder = remPositive absA absB } in if a < 0 then -remainder else remainder
63
- quotPositive :: Integral a => a -> a -> a
64
- quotPositive n d | n < d = 0 | otherwise = 1 + quotPositive (n - d) d
65
- remPositive :: Integral a => a -> a -> a
66
- remPositive n d | n < d = n | otherwise = remPositive (n - d) d
67
- div :: Integral a => a -> a -> a
68
- div _ 0 = error "divide by zero"
69
- div 0 _ = 0
70
- 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
71
- mod :: Integral a => a -> a -> a
72
- mod _ 0 = error "divide by zero"
73
- mod 0 _ = 0
74
- mod a b = a - (div a b) * b
75
- signum :: (Num a) => a -> a
76
- signum x | x == 0 = 0 | x > 0 = 1 | otherwise = -1
77
- abs :: (Num a) => a -> a
78
- abs n = if n < 0 then -n else n
79
- sqrt :: (Num a) => a -> a
80
- sqrt x = x ** 0.5
81
- max :: a -> a -> a
82
- max x y = if x <= y then y else x
83
- min :: a -> a -> a
84
- min x y = if x <= y then x else y
85
- even :: (Integral a) => a -> Bool
86
- odd :: (Integral a) => a -> Bool
87
- even n = n \`rem\` 2 == 0
88
- odd n = (not . even) n
89
- length :: [a] -> Int
90
- length [] = 0
91
- length (_:l) = 1 + length l
92
- genericLength :: (Integral a) => [b] -> a
93
- genericLength [] = 0
94
- genericLength (x:xs) = 1 + genericLength xs
95
- null :: [a] -> Bool
96
- null [] = True
97
- null (_:_) = False
98
- union :: (Eq a) => [a] -> [a] -> [a]
99
- union xs ys = unionBy (==) xs ys
100
- deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
101
- deleteBy eq x [] = []
102
- deleteBy eq x (y:ys) = if x \`eq\` y then ys else y : deleteBy eq x ys
103
- deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
104
- deleteFirstsBy eq xs ys = foldl (flip (deleteBy eq)) xs ys
105
- nubBy :: (a -> a -> Bool) -> [a] -> [a]
106
- nubBy eq [] = []
107
- nubBy eq (x:xs) = x : nubBy eq (filter (\\y -> not (eq x y)) xs)
108
- unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
109
- unionBy eq xs ys = xs ++ deleteFirstsBy eq (nubBy eq ys) xs
110
- intersect :: (Eq a) => [a] -> [a] -> [a]
111
- intersect xs ys = intersectBy (==) xs ys
112
- intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
113
- intersectBy eq xs ys = [x | x <- xs, any (eq x) ys]
114
- elem :: (Eq a) => a -> [a] -> Bool
115
- notElem :: (Eq a) => a -> [a] -> Bool
116
- elem x xs = any (\\y -> y == x) xs
117
- notElem x xs = all (\\y -> y /= x) xs
118
- maximum :: (Ord a) => [a] -> a
119
- minimum :: (Ord a) => [a] -> a
120
- maximum [] = error "Prelude.maximum: empty list"
121
- maximum xs = foldl1 max xs
122
- minimum [] = error "Prelude.minimum: empty list"
123
- minimum xs = foldl1 min xs
124
- sum :: (Num a) => [a] -> a
125
- product :: (Num a) => [a] -> a
126
- sum xs = foldl (+) 0 xs
127
- product xs = foldl (*) 1 xs
128
- concat :: [[a]] -> [a]
129
- concat xss = foldr (++) [] xss
130
- concatMap :: (a -> [b]) -> [a] -> [b]
131
- concatMap f xs = (concat . map) f xs
132
- take :: Int -> [a] -> [a]
133
- take n _ | n <= 0 = []
134
- take _ [] = []
135
- take n (x:xs) = x : take (n - 1) xs
136
- drop :: Int -> [a] -> [a]
137
- drop n xs | n <= 0 = xs
138
- drop _ [] = []
139
- drop n (_:xs) = drop (n - 1) xs
140
- head :: [a] -> a
141
- head (x:_) = x
142
- head [] = error "Prelude.head: empty list"
143
- tail :: [a] -> [a]
144
- tail (_:xs) = xs
145
- tail [] = error "Prelude.tail: empty list"
146
- last :: [a] -> a
147
- last [x] = x
148
- last (_:xs) = last xs
149
- last [] = error "Prelude.last: empty list"
150
- init :: [a] -> [a]
151
- init [x] = []
152
- init (x:xs) = x : init xs
153
- init [] = error "Prelude.init: empty list"
154
- zip :: [a] -> [b] -> [(a, b)]
155
- zip xs ys = zipWith (,) xs ys
156
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
157
- zipWith z (a:as) (b:bs) = z a b : zipWith z as bs
158
- zipWith _ _ _ = []
159
- reverse :: [a] -> [a]
160
- reverse xs = foldl (flip (:)) [] xs
161
- filter :: (a -> Bool) -> [a] -> [a]
162
- filter p [] = []
163
- filter p (x:xs) | p x = x : filter p xs | otherwise = filter p xs
164
- map :: (a -> b) -> [a] -> [b]
165
- map f [] = []
166
- map f (x:xs) = f x : map f xs
167
- any :: (a -> Bool) -> [a] -> Bool
168
- all :: (a -> Bool) -> [a] -> Bool
169
- any f (x:xs) = f x || any f xs
170
- all f (x:xs) = f x && all f xs
171
- foldl :: (a -> b -> a) -> a -> [b] -> a
172
- foldl f z [] = z
173
- foldl f z (x:xs) = foldl f (f z x) xs
174
- foldl1 :: (a -> a -> a) -> [a] -> a
175
- foldl1 f (x:xs) = foldl f x xs
176
- foldl1 _ [] = error "Prelude.foldl1: empty list"
177
- foldr :: (a -> b -> b) -> b -> [a] -> b
178
- foldr f z [] = z
179
- foldr f z (x:xs) = f x (foldr f z xs)
180
- foldr1 :: (a -> a -> a) -> [a] -> a
181
- foldr1 f [x] = x
182
- foldr1 f (x:xs) = f x (foldr1 f xs)
183
- foldr1 _ [] = error "Prelude.foldr1: empty list"
184
- find :: Ord a => (a -> Bool) -> [a] -> Maybe a
185
- find _ [] = Nothing
186
- find f (x:xs) | f x = Just x | otherwise = find f xs
187
- sort :: (Ord a) => [a] -> [a]
188
- sort xs = sortBy compare xs
189
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
190
- sortBy cmp xs = foldr (insertBy cmp) [] xs
191
- compare :: a -> a -> Ordering
192
- compare x y | x == y = EQ | x <= y = LT | otherwise = GT
193
- insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
194
- insertBy cmp x [] = [x]
195
- insertBy cmp x ys@(y:ys') = case cmp x y of { GT -> y : insertBy cmp x ys'; _ -> x : ys }
196
- flip :: (a -> b -> c) -> b -> a -> c
197
- flip f x y = f y x
198
- repeat :: a -> [a]
199
- repeat x = x : (repeat x)
200
- iterate :: (a -> a) -> a -> [a]
201
- iterate f x = x : iterate f (f x)
202
- replicate :: Int -> a -> [a]
203
- replicate n x = take n (repeat x)
204
- cycle :: [a] -> [a]
205
- cycle [] = error "Prelude.cycle: empty list"
206
- cycle xs = xs ++ (cycle 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
+ `