-- Assumes that off >= 0 def (+|) (i:n) (off:Int) : n = newOrd = ordinal i + off case newOrd < size n of True -> unsafe_from_ordinal _ newOrd False -> i -- Assumes that off >= 0 def (-|) (i:n) (off:Int) : n = newOrd = ordinal i - off case 0 <= newOrd of True -> unsafe_from_ordinal _ newOrd False -> i def pathfinder (world : rows=>cols=>Int) : cols=>Int = yield_state zero $ \costsRef. for r. costs = get costsRef costsRef := for c. world.r.c + (min costs.c $ (min costs.(c -| 1) costs.(c +| 1)))