Julio、仕様ファイル (mytypes.ads) で宣言された型
package Mytypes is
type Fruit is (Apple, Pear, Pineapple, Banana, Poison_Apple);
subtype Safe_Fruit is Fruit range Apple .. Banana;
end Mytypes;
...他のいくつかでそれを使いました:
with Mytypes;
package Parent is
function Permission (F : in Mytypes.Fruit) return Boolean;
end Parent;
...
package body Parent is
function Permission (F : in Mytypes.Fruit) return Boolean is
begin
return F in Mytypes.Safe_Fruit;
end Permission;
end Parent;
...
package Parent.Child is
procedure Eat (F : in Mytypes.Fruit);
end Parent.Child;
...
with Ada.Text_Io;
package body Parent.Child is
procedure Eat (F : in Mytypes.Fruit) is
begin
if Parent.Permission (F) then
Ada.Text_Io.Put_Line ("Eating " & Mytypes.Fruit'Image (F));
else
Ada.Text_Io.Put_Line ("Forbidden to eat " & Mytypes.Fruit'Image (F));
end if;
end Eat;
end Parent.Child;
...
with Mytypes;
with Parent.Child;
procedure Main is
begin
for I in Mytypes.Fruit'Range loop
Parent.Child.Eat (I);
end loop;
end Main;
コンパイルします:
$ gnatmake main.adb
gcc-4.4 -c parent-child.adb
gnatbind -x main.ali
gnatlink main.ali
それが実行されます:
$ ./main
Eating APPLE
Eating PEAR
Eating PINEAPPLE
Eating BANANA
Forbidden to eat POISON_APPLE
これはあなたが試したものですか?