Coding 2023-08-07
One thing that I'm not sure about when it comes to a standard library for NABTO is, what kinds of data types are useful to have? My intention is that NABTO should be usable for writing scripts to execute from the shell, simple low-traffic internet-connected operations like a small IRC bot, stuff like that. And I'd like it to scale up to bigger stuff, but I think it makes sense to nail down the behavior, and then investigate what it takes to scale it.
Anyway, there's algebraic stuff I definitely want, like booleans, optionals, lists, results, eithers (OCaml draws a distinction), maps, sets, arrays, tuples. And there definitely need to be facilities for manipulating bytes, and some kind of good interface to files full of bytes.
But I also want to have the ability to deal with text and numbers, and these abilities raise a number of questions that people feel very strongly about:
- Should there be multiple numerical types, or just one? (When there's just one, it seems to me like it's usually a 64-bit floating point type.)
- If there are distinct types for whole numbers and floats, should the whole numbers have a specified size, or be unbounded?
- If there's a bounded type for whole numbers, should there be multiple sizes? Should there be signed and unsigned variants?
- If there are different floating and whole number types, what should be required to convert between them? What about converting between different flavors within those categories?
- I probably want to represent rational numbers somehow. What representation should I use, and should it be in the core library or not?
- Assume for the moment that text is represented as utf-8 by default. (There are some libraries that I should look into, that I think would translate interestingly into a module system.) Should strings be indexed to retrieve bytes, code points, graphemes, or should they simply not be indexed at all? Keep in mind that none of these categories will always correspond to "the width of a grapheme in a fixed-width font" in a nice way.
My thoughts on this so far:
- It would be good to have facilities for using NABTO as a calculator (floating point or rational (and algebraic, if I can understand the work that's been done on algebraic representations)), and for reasoning about discrete chunks of memory and data (integers, possibly both signed and unsigned)
- I actually do have some opinions about integer operations: I think I like how Python handles integer division; that is, always rounding down, sign of non-zero remainder matches the sign of the divisor. That is, the semantics. I'm not overly attached to the // syntax.
- It would be good to have some way to get text into or out of a file, but that's not always what's going to be happening, and different types will probably be involved.
- Maybe I want to try to replicate Python 3's thing where instead of comparing some instances directly, it takes a "key" function to convert to a type that is simpler to compare. (At least sometimes. Can't do that all the time without ending up in an infinite regress.)
- Oh geez I forgot that the behavior of changing the case of text is locale-sensitive.
- I don't know if it would help with that, but I guess I should look into how Swift does things.
Anyway, it's late and I want to wrap up.
Good night.