Slide 19
Slide 19 text
第一級 Datalog constraint
19
def main(): Unit \ IO =
let facts = #{
Interpreter("x86").
Compiler("Scala", "x86", "MiniScala").
Compiler("MiniScala", "C++", "C++").
Compiler("C++", "x86", "x86").
};
let rules = #{
Compiler(src1, dst1, dst2) :-
Compiler(src1, dst1, lang1),
Compiler(lang1, dst2, lang2),
Interpreter(lang2).
Compiler(src, dst, lang) :-
Compiler(src, intermediate, lang),
Compiler(intermediate, dst, lang),
Interpreter(lang).
};
query facts, rules
select (src, dst) from Compiler(src, _, dst) |> println
Vector#{
(C++, x86),
(MiniScala, C++),
(MiniScala, x86),
(Scala, C++),
(Scala, MiniScala),
(Scala, x86)
}