zenna / Arrows.jl

14 stars 2 forks source link

Composite Source Arrows cause problems with invert #114

Open zenna opened 6 years ago

zenna commented 6 years ago

if a composite arrow is a source arrow, it will cause invert to fail. This is because the logic of invert is wrong, it turns the outport into an inport and then throws an error when it cant fix the links. Could add a special case for this but is there a more general solution?

"Broadcasted Source"
function bsource(x)
  c = CompArrow(:bsource)
  ssarr = add_sub_arr!(c, source(x))
  bsarr = add_sub_arr!(c, Arrows.BroadcastArrow())
  ◃(ssarr, 1) ⥅ ▹(bsarr, 1)
  link_to_parent!(◃(bsarr, 1))
  c

bsource!(arr::Arrow, x) = ◃(Arrows.add_sub_arr!(arr, bsource(x)), 1)

function ifelseconst()
  carr = CompArrow(:ifelseconst, [:a, :b, :c], [:z])
  a, b, c, z = ⬨(carr)
  d = ifelse(c > bsource!(carr, 3),
             a + b,
             a * b)
  d ⥅ z
  @assert is_valid(carr)
  carr
end

invert(ifelseconst())

Note, bsource! has been updated to avoid this error