I'm experimenting usage of closurse for First Order Predicate calculus, and I intend to define the following function :
func ASSUM<U, V>(p: @escaping Pred<U>) -> (Pred<U>) -> Pred<(U, V)> {
return { q in AND1(p: p, q: q) }
}
that takes as parameter a predicate p: Pred<U>
, where Pred<U>
is a typealias for (T) -> Bool
:
typealias Pred<T> = (T) -> Bool
The return of ASSUM
is a Predicate transformer closure of type (Pred<U>)->Pred<(U,V)>
.
However the compiler return the following error :
Passing non-escaping parameter 'q' to function expecting an @escaping closure
I understand that the function AND1
as defined requests an escaping parameter :
func AND1<U, V>(p: @escaping Pred<U>, q: @escaping Pred<V>) -> Pred<(U, V)> {
return { (x, y) in (p(x) && q(y)) }
}
but I did not succeed in explicitly making q
in { q in AND1(p: p, q: q) }
escaping.
How can I fix this?