Integrated Dynamics

Integrated Dynamics

63M Downloads

Apply 2 inputs to conjuncted predicates

met4000 opened this issue · 4 comments

commented

Issue type:

  • ❓ Question

Question:

I have two predicates and want to make a function that has two inputs, and returns the conjunction of the two predicates (where the first input is piped to the first predicate, and the second input is piped to the second predicate) - i.e. a signature of (Any -> Any) -> Bool.

My first thought was (ofc.) to use the conjunction operator:

PredicateA             //  Any  -> Bool
PredicateB             //  Any  -> Bool
ConjunctionOperator    // (Bool -> Bool) -> Bool

Func ← Pipe2(PredicateA, PredicateB, ConjunctionOperator)

However, Pipe2 applies its one input as the input to both PredicateA and PredicateB; Func has a signature of Any -> Bool. Since I want to be able to provide separate inputs to both PredicateA and PredicateB, this doesn't work.

My second thought was to use only Pipes and Flips (to get around the input being passed to both predicates):

PredicateA             //  Any  -> Bool
PredicateB             //  Any  -> Bool
ConjunctionOperator    // (Bool -> Bool) -> Bool

TempFunc ← Pipe(PredicateB, ConjunctionOperator)
TempFlippedFunc ← Flip(TempFunc)
Func ← Pipe(PredicateA, TempFlippedFunc)

This does result in a function that has a signature of Any -> Any -> Bool, however when I try to Apply2 values into it and place it (e.g. in a display) it gives the error: "The operator flipped received an input with type Boolean at position 1 while the type Operator was expected".

Can someone tell me where I'm going wrong, or if there's another way to achieve this?

commented

Ping @GreyMario. (FYI, there's also a Discord server where you may get help, see the readme)

commented

Conjoining predicates means you are passing one input to two different predicates and returning TRUE only if the conjoined predicates return TRUE.

Are you sure you're not overengineering this? I'm worried this is the XY problem.

It sounds like the question being asked is actually "how do I create an operator such that
AnyX -> AnyY -> Boolean with effective function [foo(X) && bar(Y)]". I'd like to verify the objective before we continue.

You're welcome to come to the Discord server for live support, though. We've gathered quite a few knowledgeable people on the subject!

commented

Sorry if my question was misleading; I'm not asking how to do it with the conjunction operator specifically, just (as you say) "how do I create an operator such that AnyX -> AnyY -> Boolean with effective function [foo(X) && bar(Y)]".

commented

Solved by @Yogghy on the discord server; I should be using the Boolean And operator, not the Conjunction operator.