// -------------------------------------------------- module TestInductiveDatatypes { // The following types test for cycles that go via instantiated type arguments datatype Record = Ctor(T); datatype RecInt = Ctor(Record); // this is fine datatype Rec_Forever = Ctor(Record); // error datatype Rec_Stops = Cons(Record, Rec_Stops) | Nil; // this is okay datatype D = Ctor(E>); // error: illegal cycle datatype E = Ctor(T); // the following is okay datatype MD = Ctor(ME); datatype ME = Ctor(T); method M() { var d: MD>; } datatype A = Ctor(B); // superficially looks like a cycle, but can still be constructed datatype B = Ctor(List); datatype List = Nil | Cons(T, List); } module MoreInductive { datatype Tree = Node(G, List>); datatype List = Nil | Cons(T, List); datatype M = All(List); datatype H<'a> = HH('a, Tree<'a>); datatype K<'a> = KK('a, Tree>); // error datatype L<'a> = LL('a, Tree>>); } // -------------------------------------------------- module TestCoinductiveDatatypes { codatatype InfList = Done | Continue(T, InfList); codatatype Stream = More(T, Stream); codatatype BinaryTreeForever = BNode(val: T, left: BinaryTreeForever, right: BinaryTreeForever); datatype List = Nil | Cons(T, List); codatatype BestBushEver = Node(value: T, branches: List>); codatatype LazyRecord = Lazy(contents: T); class MyClass { } datatype GenericDt = Blue | Green(T); datatype GenericRecord = Rec(T); datatype FiniteEnough_Class = Ctor(MyClass); datatype FiniteEnough_Co = Ctor(LazyRecord); datatype FiniteEnough_Dt = Ctor(GenericDt); // fine datatype NotFiniteEnough_Dt = Ctor(GenericRecord); // error } // --------------------------------------------------