Skip to content

Instantly share code, notes, and snippets.

@bdezonia
Created March 21, 2020 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdezonia/6eec9dfa4390562cc7176b4d578b8c7a to your computer and use it in GitHub Desktop.
Save bdezonia/6eec9dfa4390562cc7176b4d578b8c7a to your computer and use it in GitHub Desktop.
An idea for generics at the OS level
The last couple of years I have been working on a library for manipulating numeric data in generic ways
(see Zorbage: github.com/bdezonia/zorbage). The key approach is to define generic algorithms that can
work with lots of different data types. This work has been based on ideas I've been thinking about for
years and was improved by reading books by Stepanov ("Elements of Programming" and "From Mathematics to
Generic Programming").
Recently I've been thinking about saving and loading generic data types in a portable fashion. I began
toying with these ideas in a file format specification I have begun (see BSF: github.com/bdezonia/bsf).
It occurs to me that a multidimensional file reader and writer could be something provided at the OS
level. A fixed multidimensional format can be written in the same order whether you are writing float
data or RGB or YUV or strings etc. The types you read and write would provide the individual read and
write methods that would be used by the generic file reader/writer. One could say "Write this BSF with
my list of 4-bit ints" and "here is the name of the OS installed plugin that tells the OS how to read
and write 4-bit ints".
One idea I'd like to see take off is the ability to register types with the OS. A BSF reader could
handle any types that have plugins installed within the OS. Algorithms could become more resuable as
more types that can satisfy a contract are installed on the host system.
The idea of a contract (or for instance an OO class implementation) that can describe the basic
capability of a type would be very useful. That color blending app you write would work with any type
that defines the "blend" operation (whether your type is RGB48 or CMYK or YUV or Lab etc). Imagine
paint programs being freed from knowing which kind of pixel types it can support.
Anyhow contracts can become pretty minute and granular. But they also allow powerful software to be
written. In Zorbage you can raise e to a Number power. But due to similar generic definitions (a
similar contract) you can raise e to a Matrix power. Algorithms written for numbers sometimes make
sense for matrices and when they do they just work. Raising e to a matrix power is a real thing in
actuality and is used by engineers. In Zorbage this kind of thing comes for free.
These ideas would require the OS to have a preferred type/implementation language or perhaps portable
language interfaces. I have been describing an object approach but nothing would stop it from using a
functional approach.
Choosing an OS api that could have multiple program language bindings to a system of generic type
signatures might be really powerful but might be difficult.
I don't know what such a generic approach would mean for security. Having people inject "types" into
the OS would require a fucntional approach for types (no side effects allowed). There is a lot to
consider with this and I am just one curious developer.
I think the stuff I'm talking about has been in many people's heads for many many years. I just
haven't seen anybody discussing it in public. What do you think? Please comment in this reddit post.
I hope this can be a starting point for something nice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment