Re:Examples of Incorrect Abstractions in Other Languages
by JCoder58 on Tuesday May 19, 2020 @07:42PM
(#23241662)
You want F#.
> If I want to write a numeric value in a json output I'm creating that will be consumed by some other system, I want that thing to represent exactly that and spit an error if I ever try to assign something else, such as a string
https://fsharpforfunandprofit.com/posts/serializating-your-d...
> I need to be able to say, "this number is not just any number, this is actually a temperature measurement in Celsius"
https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
I like to have types when I need types. If I want to write a numeric value in a json output I'm creating that will be consumed by some other system, I want that thing to represent exactly that and spit an error if I ever try to assign something else, such as a string. But more than that, it should be easy to define my own types. I need to be able to say, "this number is not just any number, this is actually a temperature measurement in Celsius" or "this is talking about screen coordinates, not world coordinates". And then only be able to send that to the correct functions – or treat as a normal number if I'm doing basic math.
But most of the time, most people don't care about types. We want to say "do this operation across all elements of this array". If I trust whatever lower level function that added the properly typed elements in the first place, now I can focus on manipulating them. Glue code is very amenable to dynamic types.
Haskell has a very rich type system (maybe too rich?), but it also allows you to say that function receives an A and returns [A]. What's A? If you don't care, you don't care. That's beautiful. And the compiler can even inference some of it for you.
Now, if the only thing I have is a poor type system(like Java), then just give me primitives and a struct.