You're running into a fundamental design flaw in Turing. Basically,
include doesn't work like you're hoping it does.
What
include "foo.t" actually does:
- open "foo.t" and grab its contents
- put those contents in place of the include statement in the original file.
What's happening in your program:
- Main.t includes Types.t (awesome, now Assignment is defined)
- Main.t includes Calculations.t
- Calculations.t includes Types.t (now Assignment is defined
twice, in different "scopes")
The problem results because the Assignment type is defined twice, and the types are not considered to be the same.
Competent languages are designed to avoid this problem (by providing the programmer the ability to solve the problem, or by solving the problem inherently in their design). C and C++ take the former route, with #ifdef and #define, while Java and most other high-level languages take the latter route.
In Turing, the best I've been able to do is to make sure that each file is
included exactly once. You probably want:
- Calculations.t includes Types.t
- Main.t includes Calculations.t (but NOT Types.t).
It's possible to re-create this in one file, to help you understand and play with it:
Turing: |
type my_type :
record
name : string
end record
class MyClass
%import my_type
export do_something
% To make this example work, comment out this copy of my_type and uncomment
% import my_type
type my_type :
record
name : string
end record
proc do_something ( objects : array 1 .. * of my_type )
% code here...
end do_something
end MyClass
var objects : array 1..4 of my_type
var myClass : ^MyClass
new myClass
myClass -> do_something ( objects )
|