Skip to content

Commit 835d5ab

Browse files
committed
Fixing plus for inductive numbers example. Trying to fix travis for OSX
1 parent efdc449 commit 835d5ab

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ addons:
3030
before_install:
3131
- cd code
3232
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
33-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap homebrew/versions; fi
3433
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gcc48; fi
3534

3635
install:

code/test/unit/example06-smart-ptr.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ struct Nat
5959
virtual ~Nat() {}
6060
};
6161

62-
typedef std::unique_ptr<Nat> NatPtr;
63-
6462
struct O : Nat
6563
{
6664
};
6765

6866
struct S : Nat
6967
{
70-
S(Nat* n) : e(n) {}
71-
NatPtr e;
68+
S(const Nat* n) : e(n) {}
69+
~S() { if (e) delete e; }
70+
const Nat* e;
7271
};
7372

7473
//------------------------------------------------------------------------------
@@ -97,13 +96,38 @@ int evl(const Nat& n)
9796

9897
//------------------------------------------------------------------------------
9998

99+
// Add two inductively defined Nat
100+
const Nat* plus(const Nat* n, const Nat* m)
101+
{
102+
var<const Nat*> a;
103+
var<const Nat*> b;
104+
105+
Match(n, m)
106+
{
107+
108+
Case(_, C<O>()) return n; // m + 0 = m
109+
Case(C<O>(), _) return m; // 0 + m = m
110+
Case(C<S>(a), C<S>(b)) return new S(new S(plus(a, b))); // S n + S m = S (S (n + m))
111+
Otherwise() return nullptr;
112+
}
113+
EndMatch
114+
115+
XTL_UNREACHABLE; // To avoid warning that control may reach end of a non-void function
116+
}
117+
118+
//------------------------------------------------------------------------------
119+
100120
int main()
101121
{
102-
NatPtr a(new S(new S(new O)));
103-
NatPtr b(new S(new O));
122+
Nat* a = new S(new S(new O));
123+
Nat* b = new S(new O);
104124

105125
std::cout << evl(*a) << std::endl;
106126
std::cout << evl(*b) << std::endl;
127+
128+
const Nat* c = plus(a,b);
129+
130+
std::cout << evl(*c) << std::endl;
107131
}
108132

109133
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)