prelude 0.0.2 → 0.0.3
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.
- data/CHANGELOG +5 -2
- data/README +3 -3
- data/Rakefile +44 -25
- data/doc/classes/Kernel.html +198 -0
- data/doc/classes/Prelude.html +110 -3
- data/doc/classes/Prelude/EmptyListError.html +113 -0
- data/doc/classes/Prelude/List.html +1210 -1067
- data/doc/classes/Prelude/MissingFunctionError.html +113 -0
- data/doc/classes/Prelude/Monad.html +114 -57
- data/doc/classes/Prelude/Tuple.html +18 -18
- data/doc/classes/Proc.html +51 -26
- data/doc/classes/Symbol.html +65 -12
- data/doc/created.rid +1 -1
- data/doc/files/CHANGELOG.html +8 -1
- data/doc/files/README.html +3 -3
- data/doc/files/lib/prelude_rb.html +1 -1
- data/doc/fr_class_index.html +3 -0
- data/doc/fr_method_index.html +113 -97
- data/lib/prelude.rb +84 -10
- data/lib/prelude/list.rb +244 -212
- data/lib/prelude/monad.rb +88 -11
- data/test/tc_higher.rb +5 -5
- data/test/tc_list.rb +259 -268
- data/test/tc_monad.rb +145 -0
- data/test/ts_prelude.rb +2 -1
- metadata +6 -2
data/lib/prelude.rb
CHANGED
@@ -21,43 +21,117 @@
|
|
21
21
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
22
22
|
#++
|
23
23
|
#
|
24
|
-
# $Id: prelude.rb
|
24
|
+
# $Id: prelude.rb 17 2006-09-17 18:03:15Z prelude $
|
25
25
|
|
26
26
|
$:.unshift(File.dirname(__FILE__))
|
27
27
|
|
28
|
-
require 'prelude/list'
|
29
|
-
require 'prelude/tuple'
|
30
|
-
require 'prelude/monad'
|
31
|
-
|
32
28
|
module Prelude
|
33
|
-
|
29
|
+
|
30
|
+
VERSION='0.0.3'
|
31
|
+
|
32
|
+
# Returns function that returns its argument
|
33
|
+
Id = lambda { |x| x }
|
34
|
+
|
35
|
+
# Thrown if an illegal operation is performed on an empty list.
|
36
|
+
class EmptyListError < RuntimeError; end
|
37
|
+
|
38
|
+
# This is used to handle empty list errors in this library. Re-define to fit.
|
39
|
+
def empty_list_error
|
40
|
+
raise EmptyListError, 'Illegal operation on an empty list.'
|
41
|
+
end
|
42
|
+
|
43
|
+
# Thrown if no function was supplied
|
44
|
+
class MissingFunctionError < RuntimeError; end
|
45
|
+
|
46
|
+
# This is used to handle missing function errors in this library. Re-define to fit.
|
47
|
+
def missing_function_error
|
48
|
+
raise MissingFunctionError, 'No function or block supplied.'
|
49
|
+
end
|
50
|
+
|
51
|
+
# A utility to determine if a function was passed
|
52
|
+
def get_proc(f=nil, &block)
|
53
|
+
# Has to be either function 'f' or block
|
54
|
+
f = block_given? ? block : missing_function_error if f.nil?
|
55
|
+
f.to_proc
|
56
|
+
end
|
57
|
+
|
34
58
|
end # Prelude
|
35
59
|
|
36
60
|
class Symbol
|
37
61
|
|
62
|
+
# Converts a symbol to a proc object
|
38
63
|
def to_proc
|
39
64
|
proc { |obj, *args| obj.send(self, *args) }
|
40
65
|
end
|
41
66
|
|
67
|
+
# Syntaxic sugar for something like this: -:+, i.e., defines proc object that executes 'plus'.
|
68
|
+
alias -@ to_proc
|
69
|
+
|
70
|
+
# FIXIT
|
42
71
|
def curry(one, *args)
|
43
72
|
proc { |*args| self.to_proc.call(one, *args) }
|
44
73
|
end
|
45
74
|
|
75
|
+
# This is will serve as an infix composition operator for symbols. If between two symbols,
|
76
|
+
# returns composition proc, executes left symbol otherwise.
|
77
|
+
def **(*args)
|
78
|
+
if (1==args.length) && args[0].is_a?(Symbol)
|
79
|
+
proc {|*a| self.to_proc.call(args[0].call(*a)) }
|
80
|
+
else
|
81
|
+
self.to_proc.call(*args.flatten)
|
82
|
+
end
|
83
|
+
end
|
46
84
|
end # Symbol
|
47
85
|
|
48
86
|
class Proc
|
49
87
|
|
88
|
+
# Syntaxic sugar for something like this: ~head(list), i.e., gives actual head instead of proc that
|
89
|
+
# can do it if called.
|
90
|
+
alias ~ call
|
91
|
+
|
92
|
+
# FIXIT
|
50
93
|
def curry(one, *args)
|
51
|
-
|
94
|
+
lambda { |*args| self.call(one, *args)}
|
52
95
|
end
|
53
96
|
|
54
|
-
# This is will serve as an infix composition operator
|
55
|
-
|
97
|
+
# This is will serve as an infix composition operator for procs. If between two procs,
|
98
|
+
# returns composition proc, executes left proc otherwise.
|
99
|
+
def **(*args)
|
56
100
|
if (1==args.length) && args[0].is_a?(Proc)
|
57
|
-
|
101
|
+
lambda {|*a| self.call(args[0].call(*a)) }
|
58
102
|
else
|
59
103
|
self.call(*args.flatten)
|
60
104
|
end
|
61
105
|
end
|
62
106
|
|
63
107
|
end # Proc
|
108
|
+
|
109
|
+
module Kernel
|
110
|
+
|
111
|
+
# Method object for currently executing method
|
112
|
+
def this_method
|
113
|
+
name = (Kernel.caller[0] =~ /`([^']*)'/ and $1)
|
114
|
+
eval "self.method(\"#{name}\".to_sym)", binding
|
115
|
+
end
|
116
|
+
|
117
|
+
# Method object for the caller of the currently executing method
|
118
|
+
def caller_method
|
119
|
+
name = (Kernel.caller[1] =~ /`([^']*)'/ and $1)
|
120
|
+
eval "self.method(\"#{name}\".to_sym)", binding
|
121
|
+
end
|
122
|
+
|
123
|
+
# Shuts up Ruby's warning.
|
124
|
+
def silence_warnings
|
125
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
126
|
+
yield
|
127
|
+
ensure
|
128
|
+
$VERBOSE = old_verbose
|
129
|
+
end
|
130
|
+
|
131
|
+
end # Kernel
|
132
|
+
|
133
|
+
silence_warnings do
|
134
|
+
require 'prelude/list'
|
135
|
+
require 'prelude/tuple'
|
136
|
+
require 'prelude/monad'
|
137
|
+
end
|
data/lib/prelude/list.rb
CHANGED
@@ -23,332 +23,352 @@
|
|
23
23
|
|
24
24
|
module Prelude
|
25
25
|
|
26
|
-
# $Id: list.rb
|
26
|
+
# $Id: list.rb 17 2006-09-17 18:03:15Z prelude $
|
27
27
|
#
|
28
28
|
# This eventually needs to be implemented with lazy lists, see
|
29
29
|
# http://lazylist.rubyforge.org for details
|
30
30
|
#
|
31
31
|
# I used the signatures of Haskell's List.hs file in order not to forget to implement
|
32
32
|
# the functions defined there and to remind of what was intended.
|
33
|
-
|
34
|
-
# The following methods are implemented by Array with the same semantics:
|
35
|
-
# * last -- :: [a] -> a
|
36
|
-
# * length -- :: [a] -> Int
|
37
|
-
# * map -- :: (a -> b) -> [a] -> [b]
|
38
|
-
# * reverse -- :: [a] -> [a]
|
39
|
-
# * transpose -- :: [[a]] -> [[a]]
|
40
|
-
# * find -- :: (a -> Bool) -> [a] -> Maybe a
|
41
|
-
# * partition -- :: (a -> Bool) -> [a] -> ([a], [a])
|
42
|
-
# * zip -- :: [a] -> [b] -> [(a,b)]
|
43
|
-
# * sort -- :: (Ord a) => [a] -> [a]
|
44
|
-
#
|
45
|
-
# I do not know how to implement these in Ruby:
|
46
|
-
# * (!!) -- :: [a] -> Int -> a
|
47
|
-
# * (\\) -- :: (Eq a) => [a] -> [a] -> [a]
|
33
|
+
module List
|
48
34
|
|
49
|
-
|
35
|
+
# head -- :: [a] -> a
|
36
|
+
def head(list)
|
37
|
+
case list
|
38
|
+
when [] : empty_list_error
|
39
|
+
else lambda { list[0] }
|
40
|
+
end
|
41
|
+
end
|
50
42
|
|
51
|
-
#
|
43
|
+
# tail -- :: [a] -> [a]
|
44
|
+
def tail(list)
|
45
|
+
case list
|
46
|
+
when [] : empty_list_error
|
47
|
+
else lambda { list[1..-1] }
|
48
|
+
end
|
49
|
+
end
|
52
50
|
|
53
|
-
|
51
|
+
# last -- :: [a] -> a
|
52
|
+
def last(list)
|
53
|
+
case list
|
54
|
+
when [] : empty_list_error
|
55
|
+
when [list[0]] : lambda { list[0] }
|
56
|
+
else last(~tail(list))
|
57
|
+
end
|
58
|
+
end
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
# init -- :: [a] -> [a]
|
61
|
+
def init(list)
|
62
|
+
case list
|
63
|
+
when [] : empty_list_error
|
64
|
+
when [list[0]] : lambda { [] }
|
65
|
+
else lambda { [~head(list)]+~init(~tail(list)) }
|
66
|
+
end
|
57
67
|
end
|
58
68
|
|
59
|
-
#
|
60
|
-
def
|
61
|
-
|
69
|
+
# null -- :: [a] -> Bool
|
70
|
+
def null(list)
|
71
|
+
lambda { list.size == 0 }
|
62
72
|
end
|
63
|
-
|
64
|
-
#
|
65
|
-
def
|
66
|
-
|
73
|
+
|
74
|
+
# length -- :: [a] -> Int
|
75
|
+
def length(list)
|
76
|
+
lambda { list.length }
|
67
77
|
end
|
68
78
|
|
69
|
-
#
|
70
|
-
def
|
71
|
-
|
79
|
+
# map -- :: (a -> b) -> [a] -> [b]
|
80
|
+
def map(f, list)
|
81
|
+
case list
|
82
|
+
when [] : lambda{ [] }
|
83
|
+
else lambda{ [ f[~head(list)] ] + ~map(f, ~tail(list)) }
|
84
|
+
end
|
72
85
|
end
|
73
86
|
|
74
|
-
#
|
75
|
-
def
|
76
|
-
|
87
|
+
# , reverse -- :: [a] -> [a]
|
88
|
+
def reverse(list)
|
89
|
+
r = proc { |l, a|
|
90
|
+
case l
|
91
|
+
when [] : lambda { a }
|
92
|
+
else lambda { ~r[~tail(l), [~head(l)]+a] }
|
93
|
+
end
|
94
|
+
}
|
95
|
+
r[list, []]
|
77
96
|
end
|
78
97
|
|
79
98
|
# intersperse -- :: a -> [a] -> [a]
|
80
|
-
def intersperse
|
99
|
+
def intersperse(list)
|
81
100
|
warn "Method 'intersperse' is not implemented yet." if $VERBOSE
|
82
|
-
return []
|
101
|
+
return lambda { [] }
|
83
102
|
end
|
84
103
|
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
# demonstration purposes only. Use #foldl.
|
90
|
-
def f_foldl(s, &block)
|
91
|
-
empty? ? s : tail.f_foldl(block.call(s, head), &block)
|
104
|
+
# transpose -- :: [[a]] -> [[a]]
|
105
|
+
def transpose(list)
|
106
|
+
# FIXIT
|
107
|
+
lambda { list.transpose }
|
92
108
|
end
|
93
109
|
|
94
|
-
#
|
110
|
+
# # -- * Reducing lists (folds)
|
111
|
+
|
95
112
|
# foldl -- :: (a -> b -> a) -> a -> [b] -> a
|
96
|
-
def foldl(
|
97
|
-
|
113
|
+
def foldl(f, a, list)
|
114
|
+
case list
|
115
|
+
when [] : lambda { a }
|
116
|
+
else lambda { f[~foldl(f, a, ~tail(list)), ~head(list)] }
|
117
|
+
end
|
98
118
|
end
|
99
119
|
|
100
120
|
# foldl' -- :: (a -> b -> a) -> a -> [b] -> a
|
101
|
-
def foldl_
|
121
|
+
def foldl_(list)
|
102
122
|
warn "Method 'foldl_' is not implemented yet." if $VERBOSE
|
103
|
-
return []
|
123
|
+
return lambda { [] }
|
104
124
|
end
|
105
|
-
|
125
|
+
|
106
126
|
# foldl1 -- :: (a -> a -> a) -> [a] -> a
|
107
|
-
def foldl1(
|
108
|
-
|
127
|
+
def foldl1(f, list)
|
128
|
+
foldl(f, ~head(list), ~tail(list))
|
109
129
|
end
|
110
130
|
|
111
131
|
# foldl1' -- :: (a -> a -> a) -> [a] -> a
|
112
|
-
def foldl1_
|
132
|
+
def foldl1_(list)
|
113
133
|
warn "Method 'foldl1_' is not implemented yet." if $VERBOSE
|
114
|
-
return []
|
134
|
+
return lambda { [] }
|
115
135
|
end
|
116
136
|
|
117
137
|
# foldr -- :: (a -> b -> b) -> b -> [a] -> b
|
118
|
-
def foldr(s,
|
119
|
-
|
138
|
+
def foldr(f, s, list)
|
139
|
+
case list
|
140
|
+
when [] : lambda { s }
|
141
|
+
else lambda { f[~head(list), ~foldr(f, s, ~tail(list))] }
|
142
|
+
end
|
120
143
|
end
|
121
144
|
|
122
145
|
# foldr1 -- :: (a -> a -> a) -> [a] -> a
|
123
|
-
def foldr1(
|
124
|
-
|
146
|
+
def foldr1(f, list)
|
147
|
+
foldr(f, ~head(list), ~tail(list))
|
125
148
|
end
|
126
149
|
|
127
150
|
# -- ** Special folds
|
128
151
|
|
129
|
-
# Implemented by Array but semantics is different
|
130
152
|
# concat -- :: [[a]] -> [a]
|
131
|
-
def concat
|
132
|
-
|
153
|
+
def concat(list)
|
154
|
+
foldr(-:+, [], list)
|
133
155
|
end
|
134
156
|
|
135
157
|
# concatMap -- :: (a -> [b]) -> [a] -> [b]
|
136
|
-
def concat_map
|
158
|
+
def concat_map(list)
|
137
159
|
warn "Method 'concatMap' is not implemented yet." if $VERBOSE
|
138
|
-
return []
|
160
|
+
return lambda { [] }
|
139
161
|
end
|
140
162
|
alias concatMap concat_map
|
141
163
|
|
142
164
|
# and -- :: [Bool] -> Bool
|
143
|
-
def
|
144
|
-
|
165
|
+
def and_(list)
|
166
|
+
foldr(lambda {|x,y| x && y}, true, list)
|
145
167
|
end
|
146
168
|
|
147
169
|
# or -- :: [Bool] -> Bool
|
148
|
-
def
|
149
|
-
|
170
|
+
def or_(list)
|
171
|
+
foldr(lambda {|x,y| (x || y)}, false, list)
|
150
172
|
end
|
151
173
|
|
152
174
|
# any -- :: (a -> Bool) -> [a] -> Bool
|
153
|
-
def any(
|
154
|
-
|
155
|
-
return false
|
175
|
+
def any(f, list)
|
176
|
+
or_(~map(f, list))
|
156
177
|
end
|
157
178
|
|
158
179
|
# all -- :: (a -> Bool) -> [a] -> Bool
|
159
|
-
def all(
|
160
|
-
|
161
|
-
return true
|
180
|
+
def all(f, list)
|
181
|
+
and_(~map(f, list))
|
162
182
|
end
|
163
183
|
|
164
184
|
# sum -- :: (Num a) => [a] -> a
|
165
|
-
def sum
|
185
|
+
def sum(list)
|
166
186
|
warn "Method 'sum' is not implemented yet." if $VERBOSE
|
167
|
-
return []
|
187
|
+
return lambda { [] }
|
168
188
|
end
|
169
189
|
|
170
190
|
# product -- :: (Num a) => [a] -> a
|
171
|
-
def product
|
191
|
+
def product(list)
|
172
192
|
warn "Method 'product' is not implemented yet." if $VERBOSE
|
173
|
-
return []
|
193
|
+
return lambda { [] }
|
174
194
|
end
|
175
195
|
|
176
196
|
# maximum -- :: (Ord a) => [a] -> a
|
177
|
-
def maximum
|
197
|
+
def maximum(list)
|
178
198
|
warn "Method 'maximum' is not implemented yet." if $VERBOSE
|
179
|
-
return []
|
199
|
+
return lambda { [] }
|
180
200
|
end
|
181
201
|
|
182
202
|
# minimum -- :: (Ord a) => [a] -> a
|
183
|
-
def minimum
|
203
|
+
def minimum(list)
|
184
204
|
warn "Method 'minimum' is not implemented yet." if $VERBOSE
|
185
|
-
return []
|
205
|
+
return lambda { [] }
|
186
206
|
end
|
187
207
|
|
188
|
-
|
189
208
|
# -- * Building lists
|
190
209
|
|
191
210
|
# -- ** Scans
|
192
211
|
|
193
212
|
# scanl -- :: (a -> b -> a) -> a -> [b] -> [a]
|
194
|
-
def scanl(s,
|
195
|
-
|
213
|
+
def scanl(f, s, list)
|
214
|
+
warn "Method 'scanl' is not implemented yet." if $VERBOSE
|
215
|
+
return lambda { [] }
|
196
216
|
end
|
197
217
|
|
198
218
|
# scanl1 -- :: (a -> a -> a) -> [a] -> [a]
|
199
|
-
def scanl1(
|
200
|
-
|
219
|
+
def scanl1(f, list)
|
220
|
+
warn "Method 'scanl1' is not implemented yet." if $VERBOSE
|
221
|
+
return lambda { [] }
|
201
222
|
end
|
202
223
|
|
203
224
|
# scanr -- :: (a -> b -> b) -> b -> [a] -> [b]
|
204
|
-
def scanr(s,
|
205
|
-
|
225
|
+
def scanr(f, s, list)
|
226
|
+
warn "Method 'scanr' is not implemented yet." if $VERBOSE
|
227
|
+
return lambda { [] }
|
206
228
|
end
|
207
229
|
|
208
230
|
# scanr1 -- :: (a -> a -> a) -> [a] -> [a]
|
209
|
-
def scanr1(
|
210
|
-
|
231
|
+
def scanr1(f, list)
|
232
|
+
warn "Method 'scanr1' is not implemented yet." if $VERBOSE
|
233
|
+
return lambda { [] }
|
211
234
|
end
|
212
235
|
|
213
|
-
|
214
236
|
# -- ** Accumulating maps
|
215
237
|
|
216
238
|
# mapAccumL -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])
|
217
|
-
def map_accum_l
|
239
|
+
def map_accum_l(list)
|
218
240
|
warn "Method 'map_accum_l' is not implemented yet." if $VERBOSE
|
219
|
-
return []
|
241
|
+
return lambda { [] }
|
220
242
|
end
|
243
|
+
|
221
244
|
alias mapAccumL map_accum_l
|
222
245
|
|
223
246
|
# mapAccumR -- :: (a -> b -> (a,c)) -> a -> [b] -> (a,[c])
|
224
|
-
def map_accum_r
|
247
|
+
def map_accum_r(list)
|
225
248
|
warn "Method 'map_accum_r' is not implemented yet." if $VERBOSE
|
226
|
-
return []
|
249
|
+
return lambda { [] }
|
227
250
|
end
|
228
|
-
alias mapAccumR map_accum_r
|
229
251
|
|
252
|
+
alias mapAccumR map_accum_r
|
230
253
|
|
231
254
|
# -- ** Infinite lists
|
232
255
|
|
233
256
|
# iterate -- :: (a -> a) -> a -> [a]
|
234
|
-
def iterate
|
257
|
+
def iterate(list)
|
235
258
|
warn "Method 'iterate' is not implemented yet." if $VERBOSE
|
236
|
-
return []
|
259
|
+
return lambda { [] }
|
237
260
|
end
|
238
261
|
|
239
262
|
# repeat -- :: a -> [a]
|
240
|
-
def repeat
|
263
|
+
def repeat(list)
|
241
264
|
warn "Method 'repeat' is not implemented yet." if $VERBOSE
|
242
|
-
return []
|
265
|
+
return lambda { [] }
|
243
266
|
end
|
244
267
|
|
245
268
|
# replicate -- :: Int -> a -> [a]
|
246
|
-
def replicate
|
269
|
+
def replicate(list)
|
247
270
|
warn "Method 'replicate' is not implemented yet." if $VERBOSE
|
248
|
-
return []
|
271
|
+
return lambda { [] }
|
249
272
|
end
|
250
273
|
|
251
274
|
# cycle -- :: [a] -> [a]
|
252
|
-
def cycle
|
275
|
+
def cycle(list)
|
253
276
|
warn "Method 'cycle' is not implemented yet." if $VERBOSE
|
254
|
-
return []
|
277
|
+
return lambda { [] }
|
255
278
|
end
|
256
279
|
|
257
|
-
|
258
280
|
# -- ** Unfolding
|
259
281
|
|
260
282
|
# unfoldr -- :: (b -> Maybe (a, b)) -> b -> [a]
|
261
|
-
def unfoldr
|
283
|
+
def unfoldr(list)
|
262
284
|
warn "Method 'unfoldr' is not implemented yet." if $VERBOSE
|
263
|
-
return []
|
285
|
+
return lambda { [] }
|
264
286
|
end
|
265
287
|
|
266
|
-
|
267
288
|
# -- * Sublists
|
268
289
|
|
269
290
|
# -- ** Extracting sublists
|
270
291
|
|
271
292
|
# take -- :: Int -> [a] -> [a]
|
272
|
-
def take(n)
|
273
|
-
|
293
|
+
def take(n, list)
|
294
|
+
lambda { list[0..(n-1)] }
|
274
295
|
end
|
275
296
|
|
276
297
|
# drop -- :: Int -> [a] -> [a]
|
277
|
-
def drop(n)
|
278
|
-
|
298
|
+
def drop(n, list)
|
299
|
+
lambda { list[n..-1] }
|
279
300
|
end
|
280
301
|
|
281
302
|
# splitAt -- :: Int -> [a] -> ([a], [a])
|
282
|
-
def split_at(n)
|
283
|
-
[take(n), drop(n)]
|
303
|
+
def split_at(n, list)
|
304
|
+
lambda { [~take(n, list), ~drop(n, list)] }
|
284
305
|
end
|
285
|
-
alias splitAt split_at
|
286
306
|
|
287
307
|
# takeWhile -- :: (a -> Bool) -> [a] -> [a]
|
288
|
-
def take_while
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
}
|
294
|
-
r
|
308
|
+
def take_while(p, list)
|
309
|
+
case list
|
310
|
+
when [] : lambda { [] }
|
311
|
+
else p[~head(list)] ? lambda { [~head(list)]+ ~take_while(p, ~tail(list)) } : lambda { [] }
|
312
|
+
end
|
295
313
|
end
|
314
|
+
|
296
315
|
alias takeWhile take_while
|
297
316
|
|
298
317
|
# dropWhile -- :: (a -> Bool) -> [a] -> [a]
|
299
|
-
def drop_while
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
}
|
305
|
-
r
|
318
|
+
def drop_while(p, list)
|
319
|
+
case list
|
320
|
+
when [] : lambda { [] }
|
321
|
+
else p[~head(list)] ? lambda { ~drop_while(p, ~tail(list)) } : lambda { list }
|
322
|
+
end
|
306
323
|
end
|
324
|
+
|
307
325
|
alias dropWhile drop_while
|
308
326
|
|
309
327
|
# span -- :: (a -> Bool) -> [a] -> ([a], [a])
|
310
|
-
def span(
|
311
|
-
[
|
328
|
+
def span(p, list)
|
329
|
+
lambda { [~takeWhile(p, list), ~dropWhile(p,list)] }
|
312
330
|
end
|
313
331
|
|
314
332
|
# break -- :: (a -> Bool) -> [a] -> ([a], [a])
|
315
|
-
def
|
333
|
+
def break_(list)
|
316
334
|
warn "Method 'break' is not implemented yet." if $VERBOSE
|
317
|
-
return []
|
335
|
+
return lambda { [] }
|
318
336
|
end
|
319
337
|
|
320
338
|
# group -- :: Eq a => [a] -> [[a]]
|
321
|
-
def group
|
339
|
+
def group(list)
|
322
340
|
warn "Method 'group' is not implemented yet." if $VERBOSE
|
323
|
-
return []
|
341
|
+
return lambda { [] }
|
324
342
|
end
|
325
343
|
|
326
344
|
# inits -- :: [a] -> [[a]]
|
327
|
-
def inits
|
345
|
+
def inits(list)
|
328
346
|
warn "Method 'inits' is not implemented yet." if $VERBOSE
|
329
|
-
return []
|
347
|
+
return lambda { [] }
|
330
348
|
end
|
331
349
|
|
332
350
|
# tails -- :: [a] -> [[a]]
|
333
|
-
def tails
|
351
|
+
def tails(list)
|
334
352
|
warn "Method 'tails' is not implemented yet." if $VERBOSE
|
335
|
-
return []
|
353
|
+
return lambda { [] }
|
336
354
|
end
|
337
355
|
|
338
356
|
# -- ** Predicates
|
339
357
|
|
340
358
|
# isPrefixOf -- :: (Eq a) => [a] -> [a] -> Bool
|
341
|
-
def is_prefix_of
|
359
|
+
def is_prefix_of(list)
|
342
360
|
warn "Method 'is_prefix_of' is not implemented yet." if $VERBOSE
|
343
|
-
return []
|
361
|
+
return lambda { [] }
|
344
362
|
end
|
363
|
+
|
345
364
|
alias isPrefixOf is_prefix_of
|
346
365
|
|
347
366
|
# isSuffixOf -- :: (Eq a) => [a] -> [a] -> Bool
|
348
|
-
def is_suffix_of
|
367
|
+
def is_suffix_of(list)
|
349
368
|
warn "Method 'is_suffix_of' is not implemented yet." if $VERBOSE
|
350
|
-
return []
|
369
|
+
return lambda { [] }
|
351
370
|
end
|
371
|
+
|
352
372
|
alias isSuffixOf is_suffix_of
|
353
373
|
|
354
374
|
# -- * Searching lists
|
@@ -356,32 +376,44 @@ module Prelude
|
|
356
376
|
# -- ** Searching by equality
|
357
377
|
|
358
378
|
# elem -- :: a -> [a] -> Bool
|
359
|
-
def elem
|
379
|
+
def elem(list)
|
360
380
|
warn "Method 'elem' is not implemented yet." if $VERBOSE
|
361
|
-
return []
|
381
|
+
return lambda { [] }
|
362
382
|
end
|
363
383
|
|
364
384
|
# notElem -- :: a -> [a] -> Bool
|
365
|
-
def not_elem
|
385
|
+
def not_elem(list)
|
366
386
|
warn "Method 'not_elem' is not implemented yet." if $VERBOSE
|
367
|
-
return []
|
387
|
+
return lambda { [] }
|
368
388
|
end
|
389
|
+
|
369
390
|
alias notElem not_elem
|
370
|
-
|
391
|
+
|
371
392
|
# lookup -- :: (Eq a) => a -> [(a,b)] -> Maybe b
|
372
|
-
def lookup
|
393
|
+
def lookup(list)
|
373
394
|
warn "Method 'lookup' is not implemented yet." if $VERBOSE
|
374
|
-
return []
|
395
|
+
return lambda { [] }
|
375
396
|
end
|
376
397
|
|
377
398
|
# -- ** Searching with a predicate
|
378
399
|
|
400
|
+
# find -- :: (a -> Bool) -> [a] -> Maybe a
|
401
|
+
def find(p, list)
|
402
|
+
warn "Method 'find' is not implemented yet." if $VERBOSE
|
403
|
+
return lambda { [] }
|
404
|
+
end
|
405
|
+
|
379
406
|
# filter -- :: (a -> Bool) -> [a] -> [a]
|
380
|
-
def filter
|
407
|
+
def filter(list)
|
381
408
|
warn "Method 'filter' is not implemented yet." if $VERBOSE
|
382
|
-
return []
|
409
|
+
return lambda { [] }
|
383
410
|
end
|
384
411
|
|
412
|
+
# partition -- :: (a -> Bool) -> [a] -> ([a], [a])
|
413
|
+
def partition(p, list)
|
414
|
+
warn "Method 'partition' is not implemented yet." if $VERBOSE
|
415
|
+
return lambda { [] }
|
416
|
+
end
|
385
417
|
|
386
418
|
# -- * Indexing lists
|
387
419
|
|
@@ -390,167 +422,167 @@ module Prelude
|
|
390
422
|
|
391
423
|
|
392
424
|
# elemIndex -- :: (Eq a) => a -> [a] -> Maybe Int
|
393
|
-
def elem_index
|
425
|
+
def elem_index(list)
|
394
426
|
warn "Method 'elem_index' is not implemented yet." if $VERBOSE
|
395
|
-
return []
|
427
|
+
return lambda { [] }
|
396
428
|
end
|
429
|
+
|
397
430
|
alias elemIndex elem_index
|
398
431
|
|
399
432
|
# elemIndices -- :: (Eq a) => a -> [a] -> [Int]
|
400
|
-
def elem_indices
|
433
|
+
def elem_indices(list)
|
401
434
|
warn "Method 'elem_indices' is not implemented yet." if $VERBOSE
|
402
|
-
return []
|
435
|
+
return lambda { [] }
|
403
436
|
end
|
437
|
+
|
404
438
|
alias elemIndices elem_indices
|
405
439
|
|
406
440
|
# findIndex -- :: (a -> Bool) -> [a] -> Maybe Int
|
407
|
-
def find_index
|
441
|
+
def find_index(list)
|
408
442
|
warn "Method 'find_index' is not implemented yet." if $VERBOSE
|
409
|
-
return []
|
443
|
+
return lambda { [] }
|
410
444
|
end
|
445
|
+
|
411
446
|
alias findIndex find_index
|
412
447
|
|
413
448
|
# findIndices -- :: (a -> Bool) -> [a] -> [Int]
|
414
|
-
def find_indices
|
449
|
+
def find_indices(list)
|
415
450
|
warn "Method 'find_indices' is not implemented yet." if $VERBOSE
|
416
|
-
return []
|
451
|
+
return lambda { [] }
|
417
452
|
end
|
418
|
-
alias findIndices find_indices
|
419
453
|
|
454
|
+
alias findIndices find_indices
|
420
455
|
|
421
456
|
# -- * Zipping and unzipping lists
|
422
457
|
|
458
|
+
# zip -- :: [a] -> [b] -> [(a,b)]
|
459
|
+
def zip(list1, list2)
|
460
|
+
warn "Method 'zip' is not implemented yet." if $VERBOSE
|
461
|
+
return lambda { [] }
|
462
|
+
end
|
463
|
+
|
423
464
|
# zip3
|
424
|
-
def zip3
|
465
|
+
def zip3(list)
|
425
466
|
warn "Method 'zip3' is not implemented yet." if $VERBOSE
|
426
|
-
return []
|
467
|
+
return lambda { [] }
|
427
468
|
end
|
428
469
|
|
429
470
|
# zip4, zip5, zip6, zip7
|
430
|
-
def zip4
|
471
|
+
def zip4(list)
|
431
472
|
warn "Method 'zip4' is not implemented yet." if $VERBOSE
|
432
|
-
return []
|
473
|
+
return lambda { [] }
|
433
474
|
end
|
434
475
|
|
435
|
-
|
436
476
|
# zipWith -- :: (a -> b -> c) -> [a] -> [b] -> [c]
|
437
|
-
def zip_with
|
477
|
+
def zip_with(list)
|
438
478
|
warn "Method 'zip_with' is not implemented yet." if $VERBOSE
|
439
|
-
return []
|
479
|
+
return lambda { [] }
|
440
480
|
end
|
481
|
+
|
441
482
|
alias zipWith zip_with
|
442
483
|
|
443
484
|
# zipWith3
|
444
|
-
def zip_with3
|
485
|
+
def zip_with3(list)
|
445
486
|
warn "Method 'zip_with3' is not implemented yet." if $VERBOSE
|
446
|
-
return []
|
487
|
+
return lambda { [] }
|
447
488
|
end
|
489
|
+
|
448
490
|
alias zipWith3 zip_with3
|
449
491
|
|
450
492
|
# zipWith4, zipWith5, zipWith6, zipWith7
|
451
|
-
def zip_with4
|
493
|
+
def zip_with4(list)
|
452
494
|
warn "Method 'zip_with4' is not implemented yet." if $VERBOSE
|
453
|
-
return []
|
495
|
+
return lambda { [] }
|
454
496
|
end
|
455
|
-
alias zipWith4 zip_with4
|
456
497
|
|
498
|
+
alias zipWith4 zip_with4
|
457
499
|
|
458
500
|
# unzip -- :: [(a,b)] -> ([a],[b])
|
459
|
-
def unzip
|
501
|
+
def unzip(list)
|
460
502
|
warn "Method 'unzip' is not implemented yet." if $VERBOSE
|
461
|
-
return []
|
503
|
+
return lambda { [] }
|
462
504
|
end
|
463
505
|
|
464
506
|
# unzip3
|
465
|
-
def unzip3
|
507
|
+
def unzip3(list)
|
466
508
|
warn "Method 'unzip3' is not implemented yet." if $VERBOSE
|
467
|
-
return []
|
509
|
+
return lambda { [] }
|
468
510
|
end
|
469
511
|
|
470
512
|
# unzip4, unzip5, unzip6, unzip7
|
471
|
-
def unzip4
|
513
|
+
def unzip4(list)
|
472
514
|
warn "Method 'unzip4' is not implemented yet." if $VERBOSE
|
473
|
-
return []
|
515
|
+
return lambda { [] }
|
474
516
|
end
|
475
517
|
|
476
|
-
|
477
518
|
# -- * Special lists
|
478
519
|
|
479
520
|
# -- ** Functions on strings
|
480
521
|
|
481
522
|
# lines -- :: String -> [String]
|
482
|
-
def lines
|
523
|
+
def lines(list)
|
483
524
|
warn "Method 'lines' is not implemented yet." if $VERBOSE
|
484
|
-
return []
|
525
|
+
return lambda { [] }
|
485
526
|
end
|
486
527
|
|
487
528
|
# words -- :: String -> [String]
|
488
|
-
def words
|
529
|
+
def words(list)
|
489
530
|
warn "Method 'words' is not implemented yet." if $VERBOSE
|
490
|
-
return []
|
531
|
+
return lambda { [] }
|
491
532
|
end
|
492
533
|
|
493
534
|
# unlines -- :: [String] -> String
|
494
|
-
def unlines
|
535
|
+
def unlines(list)
|
495
536
|
warn "Method 'unlines' is not implemented yet." if $VERBOSE
|
496
|
-
return []
|
537
|
+
return lambda { [] }
|
497
538
|
end
|
498
539
|
|
499
540
|
# unwords -- :: [String] -> String
|
500
|
-
def unwords
|
541
|
+
def unwords(list)
|
501
542
|
warn "Method 'unwords' is not implemented yet." if $VERBOSE
|
502
|
-
return []
|
543
|
+
return lambda { [] }
|
503
544
|
end
|
504
545
|
|
505
|
-
|
506
546
|
# -- ** \"Set\" operations
|
507
547
|
|
508
548
|
# nub -- :: (Eq a) => [a] -> [a]
|
509
|
-
def nub
|
549
|
+
def nub(list)
|
510
550
|
warn "Method 'nub' is not implemented yet." if $VERBOSE
|
511
|
-
return []
|
551
|
+
return lambda { [] }
|
512
552
|
end
|
513
553
|
|
514
554
|
# delete -- :: (Eq a) => a -> [a] -> [a]
|
515
|
-
|
516
|
-
def delete(o)
|
555
|
+
def delete(o, list)
|
517
556
|
warn "Method 'delete' is not implemented yet." if $VERBOSE
|
518
|
-
return []
|
557
|
+
return lambda { [] }
|
519
558
|
end
|
520
559
|
|
521
560
|
# union -- :: (Eq a) => [a] -> [a] -> [a]
|
522
|
-
def union
|
561
|
+
def union(list)
|
523
562
|
warn "Method 'union' is not implemented yet." if $VERBOSE
|
524
|
-
return []
|
563
|
+
return lambda { [] }
|
525
564
|
end
|
526
565
|
|
527
566
|
# intersect -- :: (Eq a) => [a] -> [a] -> [a]
|
528
|
-
def intersect
|
567
|
+
def intersect(list)
|
529
568
|
warn "Method 'intersect' is not implemented yet." if $VERBOSE
|
530
|
-
return []
|
569
|
+
return lambda { [] }
|
531
570
|
end
|
532
571
|
|
533
572
|
# -- ** Ordered lists
|
534
573
|
|
535
|
-
#
|
574
|
+
# sort -- :: (Ord a) => [a] -> [a]
|
575
|
+
def sort(list)
|
576
|
+
warn "Method 'sort' is not implemented yet." if $VERBOSE
|
577
|
+
return lambda { [] }
|
578
|
+
end
|
579
|
+
|
536
580
|
# insert -- :: (Ord a) => a -> [a] -> [a]
|
537
|
-
def insert(o)
|
581
|
+
def insert(o, list)
|
538
582
|
warn "Method 'insert' is not implemented yet." if $VERBOSE
|
539
|
-
return []
|
583
|
+
return lambda { [] }
|
540
584
|
end
|
541
585
|
|
542
|
-
|
543
|
-
# def functional_fold(st, &op)
|
544
|
-
# f = proc { |s, a|
|
545
|
-
# if a.empty? then
|
546
|
-
# proc { s }
|
547
|
-
# else
|
548
|
-
# f.call(op.call(s, a[0]), a.slice(1, a.length-1))
|
549
|
-
# end
|
550
|
-
# }
|
551
|
-
# f.call(st, self)
|
552
|
-
# end
|
553
|
-
|
554
586
|
end # List
|
555
587
|
|
556
588
|
end # Prelude
|