Generic and type safe I/O model in any language
- by Eduardo León
I am looking for an I/O model, in any programming language, that is generic and type safe.
By genericity, I mean there should not be separate functions for performing the same operations on different devices (read_file, read_socket, read_terminal). Instead, a single read operation works on all read-able devices, a single write operation works on all write-able devices, and so on.
By type safety, I mean operations that do not make sense should not even be expressible in first place. Using the read operation on a non-read-able device ought to cause a type error at compile time, similarly for using the write operation on a non-write-able device, and so on.
Is there any generic and type safe I/O model?