prelude 0.0.1 → 0.0.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.
- data/CHANGELOG +11 -3
- data/COPYING +410 -247
- data/README +139 -9
- data/Rakefile +22 -19
- data/doc/classes/Prelude.html +134 -0
- data/doc/classes/Prelude/List.html +2549 -0
- data/doc/classes/Prelude/Monad.html +226 -0
- data/doc/classes/Prelude/Tuple.html +217 -0
- data/doc/classes/Proc.html +173 -0
- data/doc/classes/Symbol.html +166 -0
- data/doc/created.rid +1 -0
- data/doc/files/CHANGELOG.html +115 -0
- data/doc/files/README.html +328 -0
- data/doc/files/TODO.html +95 -0
- data/doc/files/lib/prelude/list_rb.html +83 -0
- data/doc/files/lib/prelude/monad_rb.html +83 -0
- data/doc/files/lib/prelude/tuple_rb.html +83 -0
- data/doc/files/lib/prelude_rb.html +98 -0
- data/doc/fr_class_index.html +32 -0
- data/doc/fr_file_index.html +33 -0
- data/doc/fr_method_index.html +124 -0
- data/doc/index.html +27 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/prelude.rb +12 -15
- data/lib/prelude/list.rb +115 -131
- data/lib/prelude/monad.rb +31 -19
- data/lib/prelude/tuple.rb +27 -31
- data/test/tc_higher.rb +11 -11
- data/test/tc_list.rb +29 -15
- data/test/tc_tuple.rb +49 -11
- data/test/ts_prelude.rb +11 -11
- metadata +27 -3
data/lib/prelude/monad.rb
CHANGED
@@ -6,34 +6,46 @@
|
|
6
6
|
#
|
7
7
|
# Copyright (C) 2006 APP Design, Inc.
|
8
8
|
#
|
9
|
-
# This
|
10
|
-
# it under the terms of the GNU General Public
|
11
|
-
# the Free Software Foundation; either
|
12
|
-
# (at your option) any later version.
|
9
|
+
# This library is free software; you can redistribute it and/or
|
10
|
+
# modify it under the terms of the GNU Lesser General Public
|
11
|
+
# License as published by the Free Software Foundation; either
|
12
|
+
# version 2.1 of the License, or (at your option) any later version.
|
13
13
|
#
|
14
|
-
# This
|
14
|
+
# This library is distributed in the hope that it will be useful,
|
15
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
#
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
+
# Lesser General Public License for more details.
|
18
18
|
#
|
19
|
-
# You should have received a copy of the GNU General Public
|
20
|
-
# with this
|
21
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
19
|
+
# You should have received a copy of the GNU Lesser General Public
|
20
|
+
# License along with this library; if not, write to the Free Software
|
21
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
22
22
|
#++
|
23
23
|
|
24
24
|
module Prelude
|
25
25
|
|
26
|
-
# $Id: monad.rb
|
26
|
+
# $Id: monad.rb 7 2006-09-06 17:03:26Z prelude $
|
27
27
|
#
|
28
|
-
# Monad
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
# The Monad is an Array only in an implementation sence of the word
|
29
|
+
class Monad < Array
|
30
|
+
|
31
|
+
def wrap(v)
|
32
|
+
[v]
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty
|
36
|
+
[]
|
37
|
+
end
|
38
|
+
|
39
|
+
def join
|
40
|
+
r = []
|
41
|
+
each {|a| r.push *a}
|
42
|
+
r
|
43
|
+
end
|
44
|
+
|
35
45
|
def bind(&block)
|
36
|
-
|
46
|
+
map(&block).join
|
37
47
|
end
|
48
|
+
|
38
49
|
end # Monad
|
50
|
+
|
39
51
|
end # Prelude
|
data/lib/prelude/tuple.rb
CHANGED
@@ -6,40 +6,44 @@
|
|
6
6
|
#
|
7
7
|
# Copyright (C) 2006 APP Design, Inc.
|
8
8
|
#
|
9
|
-
# This
|
10
|
-
# it under the terms of the GNU General Public
|
11
|
-
# the Free Software Foundation; either
|
12
|
-
# (at your option) any later version.
|
9
|
+
# This library is free software; you can redistribute it and/or
|
10
|
+
# modify it under the terms of the GNU Lesser General Public
|
11
|
+
# License as published by the Free Software Foundation; either
|
12
|
+
# version 2.1 of the License, or (at your option) any later version.
|
13
13
|
#
|
14
|
-
# This
|
14
|
+
# This library is distributed in the hope that it will be useful,
|
15
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
#
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
+
# Lesser General Public License for more details.
|
18
18
|
#
|
19
|
-
# You should have received a copy of the GNU General Public
|
20
|
-
# with this
|
21
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
19
|
+
# You should have received a copy of the GNU Lesser General Public
|
20
|
+
# License along with this library; if not, write to the Free Software
|
21
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
22
22
|
#++
|
23
23
|
|
24
24
|
module Prelude
|
25
25
|
|
26
|
-
# $Id: tuple.rb
|
27
|
-
#
|
26
|
+
# $Id: tuple.rb 7 2006-09-06 17:03:26Z prelude $
|
27
|
+
#
|
28
|
+
# The Tuple's being an Array should be considered an implementation inheritance.
|
28
29
|
class Tuple < Array
|
29
30
|
|
30
|
-
def
|
31
|
+
def initialize(*args)
|
31
32
|
case
|
32
33
|
when args.nil? || args.empty? :
|
33
|
-
|
34
|
-
when args.
|
35
|
-
|
36
|
-
self
|
37
|
-
when args.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
self[0] = self[1] = nil
|
35
|
+
when args.length == 1 && args[0].kind_of?(Array) :
|
36
|
+
self[0] = args[0][0]
|
37
|
+
self[1] = args[0][1..-1]
|
38
|
+
when args.length == 1 :
|
39
|
+
self[0] = args[0]
|
40
|
+
self[1] = nil
|
41
|
+
when args.length == 2 :
|
42
|
+
self[0] = args[0]
|
43
|
+
self[1] = args[1]
|
44
|
+
when args.length > 2 :
|
45
|
+
self[0] = args[0]
|
46
|
+
self[1] = args[1..-1]
|
43
47
|
end # case
|
44
48
|
end
|
45
49
|
|
@@ -51,14 +55,6 @@ module Prelude
|
|
51
55
|
self[1]
|
52
56
|
end
|
53
57
|
|
54
|
-
def fst=(o)
|
55
|
-
self[0] = o
|
56
|
-
end
|
57
|
-
|
58
|
-
def snd=(o)
|
59
|
-
self[1] = o
|
60
|
-
end
|
61
|
-
|
62
58
|
end # Tuple
|
63
59
|
|
64
60
|
end # Prelude
|
data/test/tc_higher.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: tc_higher.rb
|
2
|
+
# $Id: tc_higher.rb 7 2006-09-06 17:03:26Z prelude $
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of the Prelude library that provides tools to
|
@@ -9,19 +9,19 @@
|
|
9
9
|
#
|
10
10
|
# Copyright (C) 2006 APP Design, Inc.
|
11
11
|
#
|
12
|
-
# This
|
13
|
-
# it under the terms of the GNU General Public
|
14
|
-
# the Free Software Foundation; either
|
15
|
-
# (at your option) any later version.
|
12
|
+
# This library is free software; you can redistribute it and/or
|
13
|
+
# modify it under the terms of the GNU Lesser General Public
|
14
|
+
# License as published by the Free Software Foundation; either
|
15
|
+
# version 2.1 of the License, or (at your option) any later version.
|
16
16
|
#
|
17
|
-
# This
|
17
|
+
# This library is distributed in the hope that it will be useful,
|
18
18
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
-
#
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20
|
+
# Lesser General Public License for more details.
|
21
21
|
#
|
22
|
-
# You should have received a copy of the GNU General Public
|
23
|
-
# with this
|
24
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
22
|
+
# You should have received a copy of the GNU Lesser General Public
|
23
|
+
# License along with this library; if not, write to the Free Software
|
24
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
25
25
|
#++
|
26
26
|
|
27
27
|
class TestHigher < Test::Unit::TestCase
|
data/test/tc_list.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: tc_list.rb
|
2
|
+
# $Id: tc_list.rb 7 2006-09-06 17:03:26Z prelude $
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of the Prelude library that provides tools to
|
@@ -9,19 +9,19 @@
|
|
9
9
|
#
|
10
10
|
# Copyright (C) 2006 APP Design, Inc.
|
11
11
|
#
|
12
|
-
# This
|
13
|
-
# it under the terms of the GNU General Public
|
14
|
-
# the Free Software Foundation; either
|
15
|
-
# (at your option) any later version.
|
12
|
+
# This library is free software; you can redistribute it and/or
|
13
|
+
# modify it under the terms of the GNU Lesser General Public
|
14
|
+
# License as published by the Free Software Foundation; either
|
15
|
+
# version 2.1 of the License, or (at your option) any later version.
|
16
16
|
#
|
17
|
-
# This
|
17
|
+
# This library is distributed in the hope that it will be useful,
|
18
18
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
-
#
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20
|
+
# Lesser General Public License for more details.
|
21
21
|
#
|
22
|
-
# You should have received a copy of the GNU General Public
|
23
|
-
# with this
|
24
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
22
|
+
# You should have received a copy of the GNU Lesser General Public
|
23
|
+
# License along with this library; if not, write to the Free Software
|
24
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
25
25
|
#++
|
26
26
|
|
27
27
|
class TestList < Test::Unit::TestCase
|
@@ -114,13 +114,27 @@ class TestList < Test::Unit::TestCase
|
|
114
114
|
assert_equal(expect, result)
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
# -- * List transformations
|
119
117
|
# , map -- :: (a -> b) -> [a] -> [b]
|
120
|
-
|
118
|
+
def test_map
|
119
|
+
result = @a.map{|x| x+1}
|
120
|
+
expect = [2, 3, 4, 5, 6]
|
121
|
+
|
122
|
+
assert_equal(expect, result)
|
123
|
+
|
124
|
+
p = proc {|x| x+1}
|
125
|
+
result = @a.map(&p)
|
126
|
+
expect = [2, 3, 4, 5, 6]
|
127
|
+
|
128
|
+
assert_equal(expect, result)
|
129
|
+
end
|
121
130
|
|
122
131
|
# , reverse -- :: [a] -> [a]
|
123
|
-
|
132
|
+
def test_reverse
|
133
|
+
result = @a.reverse
|
134
|
+
expect = [5, 4, 3, 2, 1]
|
135
|
+
|
136
|
+
assert_equal(expect, result)
|
137
|
+
end
|
124
138
|
|
125
139
|
# , intersperse -- :: a -> [a] -> [a]
|
126
140
|
def test_intersperse
|
data/test/tc_tuple.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: tc_tuple.rb
|
2
|
+
# $Id: tc_tuple.rb 7 2006-09-06 17:03:26Z prelude $
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of the Prelude library that provides tools to
|
@@ -9,19 +9,19 @@
|
|
9
9
|
#
|
10
10
|
# Copyright (C) 2006 APP Design, Inc.
|
11
11
|
#
|
12
|
-
# This
|
13
|
-
# it under the terms of the GNU General Public
|
14
|
-
# the Free Software Foundation; either
|
15
|
-
# (at your option) any later version.
|
12
|
+
# This library is free software; you can redistribute it and/or
|
13
|
+
# modify it under the terms of the GNU Lesser General Public
|
14
|
+
# License as published by the Free Software Foundation; either
|
15
|
+
# version 2.1 of the License, or (at your option) any later version.
|
16
16
|
#
|
17
|
-
# This
|
17
|
+
# This library is distributed in the hope that it will be useful,
|
18
18
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
-
#
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20
|
+
# Lesser General Public License for more details.
|
21
21
|
#
|
22
|
-
# You should have received a copy of the GNU General Public
|
23
|
-
# with this
|
24
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
22
|
+
# You should have received a copy of the GNU Lesser General Public
|
23
|
+
# License along with this library; if not, write to the Free Software
|
24
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
25
25
|
#++
|
26
26
|
|
27
27
|
class TestTuple < Test::Unit::TestCase
|
@@ -35,10 +35,48 @@ class TestTuple < Test::Unit::TestCase
|
|
35
35
|
end # teardown
|
36
36
|
|
37
37
|
def test_tuple
|
38
|
+
result = Tuple.new()
|
39
|
+
expect = [nil, nil]
|
40
|
+
|
41
|
+
assert_equal(expect, result)
|
42
|
+
|
43
|
+
result = Tuple.new(1)
|
44
|
+
expect = [1, nil]
|
45
|
+
|
46
|
+
assert_equal(expect, result)
|
47
|
+
|
48
|
+
result = Tuple.new(1, 2)
|
49
|
+
expect = [1, 2]
|
50
|
+
|
51
|
+
assert_equal(expect, result)
|
52
|
+
|
53
|
+
result = Tuple.new(1, 2, 3)
|
54
|
+
expect = [1, [2, 3]]
|
55
|
+
|
56
|
+
assert_equal(expect, result)
|
57
|
+
|
58
|
+
result = Tuple.new([1, 2])
|
59
|
+
expect = [1, [2]]
|
60
|
+
|
61
|
+
assert_equal(expect, result)
|
62
|
+
|
38
63
|
result = Tuple.new([1, 2, 3, 4, 5])
|
39
64
|
expect = [1, [2, 3, 4, 5]]
|
40
65
|
|
41
66
|
assert_equal(expect, result)
|
42
67
|
end
|
43
68
|
|
69
|
+
def test_fst
|
70
|
+
result = Tuple.new(1, 2, 3).fst
|
71
|
+
expect = 1
|
72
|
+
|
73
|
+
assert_equal(expect, result)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_snd
|
77
|
+
result = Tuple.new(1, 2, 3).snd
|
78
|
+
expect = [2, 3]
|
79
|
+
|
80
|
+
assert_equal(expect, result)
|
81
|
+
end
|
44
82
|
end # TestTuple
|
data/test/ts_prelude.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: ts_prelude.rb
|
2
|
+
# $Id: ts_prelude.rb 7 2006-09-06 17:03:26Z prelude $
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of the Prelude library that provides tools to
|
@@ -9,19 +9,19 @@
|
|
9
9
|
#
|
10
10
|
# Copyright (C) 2006 APP Design, Inc.
|
11
11
|
#
|
12
|
-
# This
|
13
|
-
# it under the terms of the GNU General Public
|
14
|
-
# the Free Software Foundation; either
|
15
|
-
# (at your option) any later version.
|
12
|
+
# This library is free software; you can redistribute it and/or
|
13
|
+
# modify it under the terms of the GNU Lesser General Public
|
14
|
+
# License as published by the Free Software Foundation; either
|
15
|
+
# version 2.1 of the License, or (at your option) any later version.
|
16
16
|
#
|
17
|
-
# This
|
17
|
+
# This library is distributed in the hope that it will be useful,
|
18
18
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
-
#
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20
|
+
# Lesser General Public License for more details.
|
21
21
|
#
|
22
|
-
# You should have received a copy of the GNU General Public
|
23
|
-
# with this
|
24
|
-
# 51 Franklin Street, Fifth Floor, Boston, MA
|
22
|
+
# You should have received a copy of the GNU Lesser General Public
|
23
|
+
# License along with this library; if not, write to the Free Software
|
24
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
25
25
|
#++
|
26
26
|
|
27
27
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: prelude
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2006-09-06 00:00:00 -05:00
|
8
8
|
summary: Haskell-like functional library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: prelude@rubyforge.org
|
12
12
|
homepage: http://prelude.rubyforge.org
|
13
13
|
rubyforge_project: prelude
|
14
|
-
description: Enables Ruby programmers to use higher functions, monads, and other Haskell features.
|
14
|
+
description: Enables Ruby programmers to use higher-order functions, monads, and other Haskell features.
|
15
15
|
autorequire: prelude
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -34,6 +34,30 @@ files:
|
|
34
34
|
- TODO
|
35
35
|
- CHANGELOG
|
36
36
|
- COPYING
|
37
|
+
- doc/classes
|
38
|
+
- doc/created.rid
|
39
|
+
- doc/files
|
40
|
+
- doc/fr_class_index.html
|
41
|
+
- doc/fr_file_index.html
|
42
|
+
- doc/fr_method_index.html
|
43
|
+
- doc/index.html
|
44
|
+
- doc/rdoc-style.css
|
45
|
+
- doc/classes/Prelude
|
46
|
+
- doc/classes/Prelude.html
|
47
|
+
- doc/classes/Proc.html
|
48
|
+
- doc/classes/Symbol.html
|
49
|
+
- doc/classes/Prelude/List.html
|
50
|
+
- doc/classes/Prelude/Monad.html
|
51
|
+
- doc/classes/Prelude/Tuple.html
|
52
|
+
- doc/files/CHANGELOG.html
|
53
|
+
- doc/files/lib
|
54
|
+
- doc/files/README.html
|
55
|
+
- doc/files/TODO.html
|
56
|
+
- doc/files/lib/prelude
|
57
|
+
- doc/files/lib/prelude_rb.html
|
58
|
+
- doc/files/lib/prelude/list_rb.html
|
59
|
+
- doc/files/lib/prelude/monad_rb.html
|
60
|
+
- doc/files/lib/prelude/tuple_rb.html
|
37
61
|
- lib/prelude
|
38
62
|
- lib/prelude.rb
|
39
63
|
- lib/prelude/list.rb
|