Regarding if-branching in arithmetic: If I understand correctly, you’re looking for a way to express
if a then (b+c) else (b-c)
using only arithmetic? If so: Under some assumptions about the types of a, b, and c, the above can be expressed simply as
a*(b+c) + (1-a)*(b-c).
Another perspective: Instead of trying to figure out {how a boolean input to an IF-node could change the function in another node}, maybe think of a single curried function node of type Bool -> X -> X -> Y. Partially applying it to different values of type Bool will then give you different functions of type X -> X -> Y.
This is not what I meant (I’ve edited the post to make that clearer). I am looking for a way to naturally express that a result of a computation changes how the computation progresses. In a*(b+c) + (1-a)*(b-c) you compute both (b+c)and (b-c) . This is not what actually happens in the program.
The curried node is an interesting idea but breaks down if we move away from this toy example. If both branches contain subgraphs with a different amount of nodes and different connections between them then currying does not work (or is very unnatural).
Regarding if-branching in arithmetic: If I understand correctly, you’re looking for a way to express
if a then (b+c) else (b-c)
using only arithmetic? If so: Under some assumptions about the types of
a
,b
, andc
, the above can be expressed simply asa*(b+c) + (1-a)*(b-c)
.Another perspective: Instead of trying to figure out {how a boolean input to an IF-node could change the function in another node}, maybe think of a single curried function node of type
Bool -> X -> X -> Y
. Partially applying it to different values of typeBool
will then give you different functions of typeX -> X -> Y
.(Was that helpful?)
This is not what I meant (I’ve edited the post to make that clearer). I am looking for a way to naturally express that a result of a computation changes how the computation progresses. In
a*(b+c) + (1-a)*(b-c)
you compute both(b+c)
and(b-c)
. This is not what actually happens in the program.The curried node is an interesting idea but breaks down if we move away from this toy example. If both branches contain subgraphs with a different amount of nodes and different connections between them then currying does not work (or is very unnatural).
(Currying is a nice idea so yes)