Re:Unusual basis types in programming languages
by nyanpasu64 on Wednesday January 17, 2024 @10:07PM
(#39037161)
Are union/sum types another "basis"? Some languages include syntax for them at the level of structs, others require they be painfully hacked together out of libraries and template metaprogramming (std::variant, though bare unions exist without carrying a tag).
Re:Unusual basis types in programming languages
by mayoff on Thursday January 18, 2024 @11:54PM
(#39051686)
I also thought this was a major omission. After using languages with well-supported sum types (mainly Swift and Elm), I find it painful to go back to languages that lack native support.
Re:Unusual basis types in programming languages
by gwern on Thursday January 18, 2024 @11:59AM
(#39044212)
Covering numeric types more in depth could be interesting. It seems to surprise most people when they run into '0123' for octal or '123f' (or is that 'f123'?) for a float, '0xdeadbeef' for hex, or 'b123' for binary (is that right...? you see it so rarely I'm not sure without looking up some examples). And I'm sure there's more: surely people have come up with notations for quarternions, complex numbers, and more.
Re:Unusual basis types in programming languages
by Vecr on Thursday January 18, 2024 @02:26PM
(#39046385)
Rust also has hash sets (implemented internally with a hashmap) and B-Tree sets (implemented internally with a B-Tree map). They aren't really basis though, but in Rust almost nothing is.
Re:Unusual basis types in programming languages
by tj800x on Thursday January 18, 2024 @03:15PM
(#39047005)
Somewhat related: I'm surprised we don't see NonZero numbers (NzInts, NzNats, and NzReals, etc). This would seem to avoid a lot of division by zero problems at the type level. I realize this might "back up" checking for zeros into the origin of denominator values, but that seems like it would be an improvement to me.
Re:Unusual basis types in programming languages
by itishappy on Friday January 19, 2024 @01:35PM
(#39059240)
In the same vein, having a dedicated type for natural (or even Peano) numbers can be quite nice. I've seen some clever use-cases in Haskell and Rust such as statically enforcing bounds checks. Can't have a negative length list!
http://www.rebol.com/r3/docs/datatypes.html