Merge remote branch 'master'
[prop.git] / tests / prop3.pcc
blobd3909f46830b5400951ca0f9132dca56c15f8a1c
1 //  Test -lno-implicit-template instantiation of polymorphic types
2 #include <iostream.h>
4 datatype List<T> :: collectable printable rewrite 
5    = #[] | #[ T ... List<T> ]
6    ;
8 datatype Tree<T> :: collectable printable rewrite
9    = Empty | Leaf of T | Node of (Tree<T>, Tree<T>)
10    ;
12 datatype Foo :: collectable printable rewrite = FOO() | BAR();
14 instantiate extern datatype List<int>, Tree<List<int> >, Tree<int>, Foo;
16 Tree<int> flip(Tree<int> t)
17 {  match (t)
18    {  Node(a,b): { return Node(flip(b),flip(a)); }
19    |  t:         { return t; }
20    }
23 #define PROP_EXPLICIT_TEMPLATE_INSTANTIATION
24 instantiate datatype List<int>, Tree<List<int> >, Tree<int>, Foo;
26 int main()
27 {  List<int> a = #[1,2,3];
28    Tree<List<int> > empty = Empty; // fake it for now
29    Tree<List<int> > b = Node(Leaf(#[4]),Node(Leaf(#[5,6]),empty));
30    Tree<int> c = Node(Leaf(4),Node(Leaf(5),Leaf(6)));
31    for (int i = 0; i < 10000; i++) 
32    {  Foo f = FOO(); }
33    cout << "a = " << a << endl;
34    cout << "b = " << b << endl;
35    cout << "c = " << c << endl;
36    return 0;