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.
@@ -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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # $Id: ts_prelude.rb 7 2006-09-06 17:03:26Z prelude $
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.2
7
- date: 2006-09-06 00:00:00 -05:00
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: