prelude 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- 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/test/tc_monad.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: tc_monad.rb 13 2006-09-11 05:19:16Z prelude $
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of the Prelude library that provides tools to
|
6
|
+
# enable Haskell style functional programming in Ruby.
|
7
|
+
#
|
8
|
+
# http://prelude.rubyforge.org
|
9
|
+
#
|
10
|
+
# Copyright (C) 2006 APP Design, Inc.
|
11
|
+
#
|
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
|
+
#
|
17
|
+
# This library is distributed in the hope that it will be useful,
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20
|
+
# Lesser General Public License for more details.
|
21
|
+
#
|
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
|
+
#++
|
26
|
+
|
27
|
+
# A test class representing a genesis of a possible cloned animal
|
28
|
+
class Cloned
|
29
|
+
include Monad
|
30
|
+
|
31
|
+
attr_reader :name, :mother, :father
|
32
|
+
|
33
|
+
def initialize(n, m, f)
|
34
|
+
@name = n
|
35
|
+
@mother = m
|
36
|
+
@father = f
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
self.nil? ? 'null' : name
|
41
|
+
end
|
42
|
+
|
43
|
+
# Traditional versions
|
44
|
+
def maternalGrandfather
|
45
|
+
mother ? mother.father : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def mothersPaternalGrandfather
|
49
|
+
mother ? (mother.father ? mother.father.father : nil) : nil
|
50
|
+
end
|
51
|
+
|
52
|
+
# Monadic versions
|
53
|
+
def m_maternalGrandfather
|
54
|
+
wrap << :mother << :father << unwrap
|
55
|
+
end
|
56
|
+
|
57
|
+
def m_mothersPaternalGrandfather
|
58
|
+
wrap.bind(:mother).bind(:father).bind(:father).unwrap
|
59
|
+
end
|
60
|
+
end # Cloned
|
61
|
+
|
62
|
+
class TestMonad < Test::Unit::TestCase
|
63
|
+
|
64
|
+
def setup
|
65
|
+
@grandgrandpa = Cloned.new('Grandgrandpa', nil, nil)
|
66
|
+
@grandma = Cloned.new('Grandma', nil, @grandgrandpa)
|
67
|
+
@grandpa = Cloned.new('Grandpa', nil, nil)
|
68
|
+
@daddy = Cloned.new('Daddy', @grandma, nil)
|
69
|
+
@mommy = Cloned.new('Mommy', nil, @grandpa)
|
70
|
+
@sheep = Cloned.new('Dolly', @mommy, @daddy)
|
71
|
+
end # setup
|
72
|
+
|
73
|
+
def teardown
|
74
|
+
# Nothing
|
75
|
+
end # teardown
|
76
|
+
|
77
|
+
def test_monad
|
78
|
+
result = [nil, nil]
|
79
|
+
expect = [nil, nil]
|
80
|
+
|
81
|
+
assert_equal(expect, result)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_no_bind
|
85
|
+
result = @sheep.maternalGrandfather
|
86
|
+
expect = @grandpa
|
87
|
+
|
88
|
+
assert_equal(expect, result)
|
89
|
+
|
90
|
+
result = @sheep.mothersPaternalGrandfather
|
91
|
+
expect = nil
|
92
|
+
|
93
|
+
assert_equal(expect, result)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_bind1
|
97
|
+
result = @sheep.m_maternalGrandfather
|
98
|
+
expect = @grandpa
|
99
|
+
|
100
|
+
assert_equal(expect, result)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_bind2
|
104
|
+
result = @sheep.m_mothersPaternalGrandfather
|
105
|
+
expect = nil
|
106
|
+
|
107
|
+
assert_equal(expect, result)
|
108
|
+
end
|
109
|
+
|
110
|
+
def aaa(one, two=222, *args, &block)
|
111
|
+
puts 'aaa: '
|
112
|
+
puts 'one=' + one.inspect
|
113
|
+
puts 'two=' + two.inspect
|
114
|
+
args.each{|x| puts 'p= '+x.inspect}
|
115
|
+
puts 'b= '+block.inspect
|
116
|
+
bbb
|
117
|
+
end
|
118
|
+
|
119
|
+
def bbb
|
120
|
+
puts 'AAA: '+caller_method.inspect
|
121
|
+
puts 'Arity: '+caller_method.to_proc.arity.inspect
|
122
|
+
end
|
123
|
+
|
124
|
+
# def test_method
|
125
|
+
# p = proc {}
|
126
|
+
# # aaa()
|
127
|
+
# aaa(1)
|
128
|
+
# aaa(1, "aaa")
|
129
|
+
# # aaa(){|x| x+1}
|
130
|
+
# aaa(1){|x| x+1}
|
131
|
+
# aaa(1, 2, 3){|x| x+1}
|
132
|
+
# aaa(1, 2, :aaa, 3){|x| x+1}
|
133
|
+
# aaa(1, proc {|x| x+1}, :aaa, 3){|x| x+1}
|
134
|
+
# aaa(proc {|x| x+1})
|
135
|
+
# aaa([1, 2, 3])
|
136
|
+
# aaa([1, 2, 3])
|
137
|
+
# aaa(*[1, 2, 3, p])
|
138
|
+
# aaa(*[1, 2, 3, p], &p)
|
139
|
+
# end
|
140
|
+
|
141
|
+
# def test_misc
|
142
|
+
# puts "this: "+ this_method.inspect
|
143
|
+
# puts "caller: "+caller_method.inspect
|
144
|
+
# end
|
145
|
+
end # TestMonad
|
data/test/ts_prelude.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# $Id: ts_prelude.rb
|
2
|
+
# $Id: ts_prelude.rb 12 2006-09-07 20:50:50Z prelude $
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# This file is part of the Prelude library that provides tools to
|
@@ -33,3 +33,4 @@ require 'test/unit'
|
|
33
33
|
require 'tc_list'
|
34
34
|
require 'tc_higher'
|
35
35
|
require 'tc_tuple'
|
36
|
+
require 'tc_monad'
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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-09-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2006-09-17 00:00:00 -05:00
|
8
8
|
summary: Haskell-like functional library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -42,11 +42,14 @@ files:
|
|
42
42
|
- doc/fr_method_index.html
|
43
43
|
- doc/index.html
|
44
44
|
- doc/rdoc-style.css
|
45
|
+
- doc/classes/Kernel.html
|
45
46
|
- doc/classes/Prelude
|
46
47
|
- doc/classes/Prelude.html
|
47
48
|
- doc/classes/Proc.html
|
48
49
|
- doc/classes/Symbol.html
|
50
|
+
- doc/classes/Prelude/EmptyListError.html
|
49
51
|
- doc/classes/Prelude/List.html
|
52
|
+
- doc/classes/Prelude/MissingFunctionError.html
|
50
53
|
- doc/classes/Prelude/Monad.html
|
51
54
|
- doc/classes/Prelude/Tuple.html
|
52
55
|
- doc/files/CHANGELOG.html
|
@@ -65,6 +68,7 @@ files:
|
|
65
68
|
- lib/prelude/tuple.rb
|
66
69
|
- test/tc_higher.rb
|
67
70
|
- test/tc_list.rb
|
71
|
+
- test/tc_monad.rb
|
68
72
|
- test/tc_tuple.rb
|
69
73
|
- test/ts_prelude.rb
|
70
74
|
test_files:
|