// Souffle - A Datalog Compiler
// Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt



.comp NumGenerator {
    .decl R(n:number)
}

.comp LotsOfNumGenerator : NumGenerator {
    R(0).
    R(n+1) :- R(n), n <= 10.
}

.comp BiggerNumGenerator : LotsOfNumGenerator {
    R(22).
}

.comp NumSelector<T> {
    .init generator = T
    .decl Selected(n: number)
    Selected(n) :- generator.R(n), generator.R(n*2).
}

.comp GoodNumSelector<T> : NumSelector<T> {
    Selected(42).
}

.comp Main<TSelector, TGenerator> {
    .init selector = TSelector<TGenerator>
    .decl Out(n:number)
.output Out()
    Out(x) :- selector.Selected(x).
}

.init main1 = Main<NumSelector, LotsOfNumGenerator>
.init main2 = Main<GoodNumSelector, LotsOfNumGenerator> // selects 42, even if it is not generated
.init main3 = Main<NumSelector, BiggerNumGenerator> // selects 22 = 2*11

