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.
@@ -6,34 +6,46 @@
6
6
  #
7
7
  # Copyright (C) 2006 APP Design, Inc.
8
8
  #
9
- # This program is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
20
- # with this program; if not, write to the Free Software Foundation, Inc.,
21
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 2 2006-08-25 00:11:17Z prelude $
26
+ # $Id: monad.rb 7 2006-09-06 17:03:26Z prelude $
27
27
  #
28
- # Monad implementation is inspired by the following sources:
29
- #
30
- # * article "Late to the Party" posted at http://cwilliams.textdriven.com/pages/monads, I could not detect
31
- # the author's name
32
- # * writings by MenTaLguY, see http://moonbase.rydia.net/mental/writings/programming/monads-in-ruby/00introduction.html
33
- #
34
- class Monad
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
- collect(&block).flatten
46
+ map(&block).join
37
47
  end
48
+
38
49
  end # Monad
50
+
39
51
  end # Prelude
@@ -6,40 +6,44 @@
6
6
  #
7
7
  # Copyright (C) 2006 APP Design, Inc.
8
8
  #
9
- # This program is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
20
- # with this program; if not, write to the Free Software Foundation, Inc.,
21
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 2 2006-08-25 00:11:17Z prelude $
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 new(*args)
31
+ def initialize(*args)
31
32
  case
32
33
  when args.nil? || args.empty? :
33
- super.new([nil, nil])
34
- when args.lengh == 1 && args[0].kind_of(Array) :
35
- super.new(args[0][0])
36
- self << super.new([args[0][1..-1]])
37
- when args.lengh == 1 :
38
- super.new([args[0], nil])
39
- when args.lengh == 2 :
40
- super.new(args)
41
- when args.lengh > 2 :
42
- super.new([args[0], args[1..-1]])
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: tc_higher.rb 1 2006-08-24 20:34:21Z prelude $
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 program is free software; you can redistribute it and/or modify
13
- # it under the terms of the GNU General Public License as published by
14
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
23
- # with this program; if not, write to the Free Software Foundation, Inc.,
24
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: tc_list.rb 1 2006-08-24 20:34:21Z prelude $
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 program is free software; you can redistribute it and/or modify
13
- # it under the terms of the GNU General Public License as published by
14
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
23
- # with this program; if not, write to the Free Software Foundation, Inc.,
24
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
- # already defined by the Array
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
- # already defined by the Array
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: tc_tuple.rb 1 2006-08-24 20:34:21Z prelude $
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 program is free software; you can redistribute it and/or modify
13
- # it under the terms of the GNU General Public License as published by
14
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
23
- # with this program; if not, write to the Free Software Foundation, Inc.,
24
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: ts_prelude.rb 1 2006-08-24 20:34:21Z prelude $
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 program is free software; you can redistribute it and/or modify
13
- # it under the terms of the GNU General Public License as published by
14
- # the Free Software Foundation; either version 2 of the License, or
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 program is distributed in the hope that it will be useful,
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
- # GNU General Public License for more details.
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 License along
23
- # with this program; if not, write to the Free Software Foundation, Inc.,
24
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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.1
7
- date: 2006-08-24 00:00:00 -05:00
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