You don't have that API. You offer
x = read_guess(0)
y = read_name("what's your name: ", len(x))
z = read_guess(len(x)+len(y))
If you read(0) twice, you get the same value both times.
Re:Moving Beyond Type Systems
by mitt_romney_12 on Saturday June 01, 2024 @12:03PM
(#40546843)
But now every function that reads from stdin needs to pass around an offset of where to read from which is very unergonomical. It also isn't really pure since offset is now state that is changing whenever a function is called.
fn do_stuff(offset: int) -> (string, int) { x = read_guess(offset) y = read_name("what's your name: ", offset + len(x)) z = read_guess(offset+len(x)+len(y)) new_offset = offset+len(x)+len(y)+len(z) return ("name is: {y}, guess is: {x}", new_offset) }
Ergonomics isn't really the point of a hypothetical extreme system. And no, you can compute offset as a result of all inputs to the system, like I did in my example - just keep passing a "previous state" value around, and compute the next state and return it. Like any other functional system already does 99% of the time.
x = read_guess(); y = io.read_int("what's your name: "); z = read_guess();
How would your system ensure x and z are the same?