prelude 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +25 -1
  2. data/README +11 -12
  3. data/Rakefile +6 -10
  4. data/lib/prelude.rb +36 -91
  5. data/lib/prelude/{tuple.rb → array_list.rb} +30 -27
  6. data/lib/prelude/functions.rb +414 -0
  7. data/lib/prelude/functors.rb +72 -0
  8. data/lib/prelude/lambda.rb +89 -0
  9. data/lib/prelude/minimal_array_list.rb +61 -0
  10. data/lib/prelude/monad.rb +11 -15
  11. data/lib/prelude/proper_list.rb +47 -0
  12. data/lib/prelude/proper_ruby_list.rb +48 -0
  13. data/lib/prelude/util.rb +33 -0
  14. data/test/tc_functions.rb +801 -0
  15. data/test/tc_monad.rb +21 -41
  16. data/test/ts_prelude.rb +2 -8
  17. metadata +13 -36
  18. data/doc/classes/Kernel.html +0 -198
  19. data/doc/classes/Prelude.html +0 -241
  20. data/doc/classes/Prelude/EmptyListError.html +0 -113
  21. data/doc/classes/Prelude/List.html +0 -2692
  22. data/doc/classes/Prelude/MissingFunctionError.html +0 -113
  23. data/doc/classes/Prelude/Monad.html +0 -283
  24. data/doc/classes/Prelude/Tuple.html +0 -217
  25. data/doc/classes/Proc.html +0 -198
  26. data/doc/classes/Symbol.html +0 -219
  27. data/doc/created.rid +0 -1
  28. data/doc/files/CHANGELOG.html +0 -122
  29. data/doc/files/README.html +0 -328
  30. data/doc/files/TODO.html +0 -95
  31. data/doc/files/lib/prelude/list_rb.html +0 -83
  32. data/doc/files/lib/prelude/monad_rb.html +0 -83
  33. data/doc/files/lib/prelude/tuple_rb.html +0 -83
  34. data/doc/files/lib/prelude_rb.html +0 -98
  35. data/doc/fr_class_index.html +0 -35
  36. data/doc/fr_file_index.html +0 -33
  37. data/doc/fr_method_index.html +0 -140
  38. data/doc/index.html +0 -27
  39. data/doc/rdoc-style.css +0 -208
  40. data/lib/prelude/list.rb +0 -588
  41. data/test/tc_higher.rb +0 -89
  42. data/test/tc_list.rb +0 -777
  43. data/test/tc_tuple.rb +0 -82
@@ -1,328 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>File: README</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <!-- banner header -->
50
-
51
- <div id="bodyContent">
52
-
53
-
54
-
55
- <div id="contextContent">
56
-
57
- <div id="description">
58
- <h1><a href="../classes/Prelude.html">Prelude</a> - a Haskell-like functional library</h1>
59
- <p>
60
- $Id: README 17 2006-09-17 18:03:15Z prelude $
61
- </p>
62
- <p>
63
- <b>WARNING</b> <tt>The project is still in a very preliminary state. Only
64
- List was partially implemented. Feel free to contribute.</tt>
65
- </p>
66
- <p>
67
- Project home is at <a
68
- href="http://rubyforge.org/projects/prelude">rubyforge.org/projects/prelude</a>/
69
- </p>
70
- <h2>The goal</h2>
71
- <p>
72
- The general idea is that functional programming provides many benefits,
73
- which are not directly available in Ruby out of the box. This library will,
74
- hopefully, provide an infrastructure for the use of most Haskell&#8217;s
75
- functional idioms. It will also facilitate a more or less direct port to
76
- Ruby of algorithms and data structures already developed by functional
77
- community. I deem infinite lists, monads, and higher-level functions to be
78
- most useful functional contribution to the general purpose programming.
79
- </p>
80
- <p>
81
- I do believe the old math&#8217;s maxim that &quot;new notation leads to
82
- new results.&quot;
83
- </p>
84
- <h2>Features</h2>
85
- <p>
86
- As of right now, i.e., release 0.0.x, the feature list is pretty much a
87
- wish list, so treat it accordingly.
88
- </p>
89
- <h3>Rather curious collection of operations on lists</h3>
90
- <p>
91
- Haskell&#8217;s lists are different from Ruby&#8217;s arrays in many ways.
92
- First of all, there are more operations defined on lists and the naming
93
- convention is different. Since Haskell&#8217;s (or Lisp&#8217;s) lists play
94
- a fundamental role in everything functional, their implementation seems
95
- necessary. Here are the goals for list&#8217;s implementation:
96
- </p>
97
- <ul>
98
- <li>Most, if not all, functions, i.e., <tt>head</tt>, <tt>tail</tt>,
99
- <tt>last</tt>, <tt>first</tt>, <tt>concat</tt>, etc.
100
-
101
- </li>
102
- <li>Assignment compatibility with Ruby&#8217;s native arrays. For example,
103
- these operations should be correct:
104
-
105
- <pre>
106
- List a = List.new([1, 2, 3])
107
- b = [3, 4, 5]
108
- List c = a+b
109
- a[1] = 10
110
- b[2] = a[3]
111
- a &lt;&lt; 3 &lt;&lt; 4
112
- </pre>
113
- <p>
114
- &#8230;and so on.
115
- </p>
116
- </li>
117
- <li>List comprehension. It&#8217;s mostly covered by Ruby&#8217;s own
118
- functionality, but some semantic refinements may be needed.
119
-
120
- </li>
121
- <li>Infinite lists. It might look like this:
122
-
123
- <pre>
124
- List ones = List.new([1]) { ones } # =&gt; [1,... ]
125
- ones.take 3 # =&gt; [1, 1, 1]
126
- </pre>
127
- <p>
128
- This functionality is being developed by the Lazilists project, see <a
129
- href="http://lazylist.rubyforge.org">lazylist.rubyforge.org</a>
130
- </p>
131
- </li>
132
- <li>What else?
133
-
134
- </li>
135
- </ul>
136
- <h3>Reinforced Ruby&#8217;s Lambda-calculus</h3>
137
- <p>
138
- While implementing majority of the Lambda world is relatively trivial in
139
- Ruby, some of the recursive beauty might be lost. Consider <tt>foldl</tt>,
140
- for example. The classic recursive definition like this
141
- </p>
142
- <pre>
143
- def foldl(s, &amp;block)
144
- empty? ? s : tail.foldl(block.call(s, head), &amp;block)
145
- end
146
- </pre>
147
- <p>
148
- croaks on about 800+ elements integer lists, but more rubyish and compact
149
- </p>
150
- <pre>
151
- def foldl(s, &amp;block)
152
- inject(s){ |a,b| block.call(a,b) }
153
- end
154
- </pre>
155
- <p>
156
- does not possess any of the classic&#8217;s functional elegance. It means
157
- that for practical applications Ruby&#8217;s recursions need to be fixed or
158
- somehow re-implemented in the <a href="../classes/Prelude.html">Prelude</a>
159
- library.
160
- </p>
161
- <h3>Higher-order functions</h3>
162
- <p>
163
- It is a very good thing, that Ruby allows functions to be good citizens
164
- including being passed to other functions and returned from them. These
165
- need to be added to complete the picture:
166
- </p>
167
- <ul>
168
- <li>Function combinations. Consider:
169
-
170
- <pre>
171
- add5 = proc {|x| x+5}
172
- add6 = proc {|x| x+6}
173
- add11 = add5 &lt;&lt; add6
174
- </pre>
175
- <p>
176
- I.e., the <tt>add5</tt> is an absolutely generic algorithm expressed in
177
- terms of other functions as long as <tt>add5</tt> takes as an argument and
178
- <tt>add6</tt> returns an object for which operation <tt>+</tt> is defined.
179
- </p>
180
- </li>
181
- <li>Currying, as in
182
-
183
- <pre>
184
- add5 = (proc {|x,y,z| x+y+z}).curry(5)
185
- add5.call(3, 2) # =&gt; 10
186
- </pre>
187
- <p>
188
- More convenient syntax is desirable.
189
- </p>
190
- </li>
191
- <li>What else?
192
-
193
- </li>
194
- </ul>
195
- <h3>Monads</h3>
196
- <p>
197
- This is where all the previous trouble should start paying off allowing an
198
- application to be structured like this:
199
- </p>
200
- <pre>
201
- result &lt;&lt; connect &lt;&lt; do_something &lt;&lt; delete_something &lt;&lt; with(params)
202
- </pre>
203
- <p>
204
- Writing tutorials for monadic computations became a little industry in
205
- itself, see <a
206
- href="http://nomaware.com/monads/html/index.html">nomaware.com/monads/html/index.html</a>
207
- to get started. More monadic resources are here: <a
208
- href="http://haskell.org/haskellwiki/Books_and_tutorials#Using_monads">haskell.org/haskellwiki/Books_and_tutorials#Using_monads</a>
209
- </p>
210
- <h3>What else?</h3>
211
- <p>
212
- These features will be nice to have in a second release of the library:
213
- </p>
214
- <ul>
215
- <li>General purpose monadic parser library similar to Parsec, see <a
216
- href="http://www.cs.uu.nl/~daan/parsec.html">www.cs.uu.nl/~daan/parsec.html</a>
217
-
218
- </li>
219
- <li>Tools for automatic program verification and algebraic proofs
220
-
221
- </li>
222
- <li>What else?
223
-
224
- </li>
225
- </ul>
226
- <h2>What&#8217;s in a name</h2>
227
- <p>
228
- Since most of the functionality to be implemented here is defined in
229
- Haskell&#8217;s prelude package, the name <b><a
230
- href="../classes/Prelude.html">Prelude</a></b> seemed natural.
231
- </p>
232
- <h2>Download</h2>
233
- <p>
234
- The latest <a href="../classes/Prelude.html">Prelude</a> library version
235
- can be downloaded from <a
236
- href="http://rubyforge.org/frs/?group_id=2096">rubyforge.org/frs/?group_id=2096</a>
237
- </p>
238
- <h2>Installation</h2>
239
- <p>
240
- You can install <a href="../classes/Prelude.html">Prelude</a> library with
241
- the following command.
242
- </p>
243
- <pre>
244
- % gem install prelude
245
- </pre>
246
- <h2>License</h2>
247
- <p>
248
- <a href="../classes/Prelude.html">Prelude</a> library is released under the
249
- Lesser GPL license, see <a
250
- href="http://www.gnu.org/licenses/lgpl.txt">www.gnu.org/licenses/lgpl.txt</a>
251
- </p>
252
- <h2>Support</h2>
253
- <p>
254
- Please use the following:
255
- </p>
256
- <ul>
257
- <li>forums on Rubyforge for general discussions, <a
258
- href="http://rubyforge.org/forum/?group_id=2096">rubyforge.org/forum/?group_id=2096</a>
259
-
260
- </li>
261
- <li>trackers to submit bugs or feature requests, <a
262
- href="http://rubyforge.org/tracker/?group_id=2096">rubyforge.org/tracker/?group_id=2096</a>
263
-
264
- </li>
265
- <li>to contact the author, send mail to prelude rubyforge org
266
-
267
- </li>
268
- </ul>
269
- <h2>References</h2>
270
- <p>
271
- The authors of the project were inspired by the following works:
272
- </p>
273
- <ol>
274
- <li>An article, probably by Gavin Sinclair, at <a
275
- href="http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc">blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc</a>
276
- regarding <a href="../classes/Symbol.html#M000001">Symbol#to_proc</a>
277
- function in Ruby Extension project, <a
278
- href="http://extensions.rubyforge.org">extensions.rubyforge.org</a>
279
-
280
- </li>
281
- <li>An elaborate port of Perl&#8217;s Sub::Curry library by Ross Bamford, <a
282
- href="http://rubyforge.org/projects/rubymurray">rubyforge.org/projects/rubymurray</a>
283
-
284
- </li>
285
- <li>An early implementation of Haskell&#8217;s lists as Ruby arrays by Hipster
286
- (a.k.a. Michel van de Ven). His original sketch can be found at <a
287
- href="http://www.xs4all.nl/~hipster/lib/ruby/haskell">www.xs4all.nl/~hipster/lib/ruby/haskell</a>
288
-
289
- </li>
290
- <li>An article by Christopher Williams &quot;Late to the Party&quot; posted at
291
- <a
292
- href="http://cwilliams.textdriven.com/pages/monads">cwilliams.textdriven.com/pages/monads</a>
293
-
294
- </li>
295
- <li>Several articles on monads by MenTaLguY, see <a
296
- href="http://moonbase.rydia.net/mental/writings/programming/monads-in-ruby/00introduction.html">moonbase.rydia.net/mental/writings/programming/monads-in-ruby/00introduction.html</a>
297
-
298
- </li>
299
- </ol>
300
-
301
- </div>
302
-
303
-
304
- </div>
305
-
306
-
307
- </div>
308
-
309
-
310
- <!-- if includes -->
311
-
312
- <div id="section">
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
- <!-- if method_list -->
322
-
323
-
324
- </div>
325
-
326
-
327
- </body>
328
- </html>
@@ -1,95 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>File: TODO</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <!-- banner header -->
50
-
51
- <div id="bodyContent">
52
-
53
-
54
-
55
- <div id="contextContent">
56
-
57
- <div id="description">
58
- <h1>TODO list</h1>
59
- <p>
60
- $Id: TODO 2 2006-08-25 00:11:17Z prelude $
61
- </p>
62
- <p>
63
- Please refer to the task list on Rubyforge site for all outstanding tasks,
64
- see <a
65
- href="http://rubyforge.org/pm/?group_id=2096">rubyforge.org/pm/?group_id=2096</a>
66
- </p>
67
-
68
- </div>
69
-
70
-
71
- </div>
72
-
73
-
74
- </div>
75
-
76
-
77
- <!-- if includes -->
78
-
79
- <div id="section">
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
- <!-- if method_list -->
89
-
90
-
91
- </div>
92
-
93
-
94
- </body>
95
- </html>
@@ -1,83 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>File: list.rb</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <!-- banner header -->
50
-
51
- <div id="bodyContent">
52
-
53
-
54
-
55
- <div id="contextContent">
56
-
57
-
58
-
59
- </div>
60
-
61
-
62
- </div>
63
-
64
-
65
- <!-- if includes -->
66
-
67
- <div id="section">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
- <!-- if method_list -->
77
-
78
-
79
- </div>
80
-
81
-
82
- </body>
83
- </html>