|
|
|
|
|
by jaen
29 days ago
|
|
OCaml and Scala, both also famously strongly typed functional languages, also have structural typing (OCaml even has many different kinds at many different levels!). Mainstream, Go is based on structural (interface) typing. The Person/Wine example is a pointless strawman. That's not what structural typing is generally used for. The entire comment is basically making up strawmans...
I didn't give practical examples to save space, obviously, it was just to disambiguate what I meant. TypeScript has several runtime-safe advanced validators based on its type system (most well-known being Zod), capable of enforcing types similar to what I provided. To conclude, these type system features were added by multiple experienced language designers for a reason, to languages that already had functional ADTs, so going "huh but what are these even useful for?!" to me sounds a bit clueless (or argumentative), so I don't see a productive continuation to this discussion. |
|
> these type system features were added by multiple experienced language designers for a reason
Oooh, an appeal to authority, where that authority isn't even named. I'll have you know a famous queen told me you're wrong on this, also for "a reason".
> TypeScript has several runtime-safe advanced validators based on its type system (most well-known being Zod), capable of enforcing types similar to what I provided.
Right, so TS typing is so amazing it requires runtime parser libraries from NPM, and Haskell is less sophisticated because it's not stringly typed.
You realise the entire, complete, exhaustive runtime schema for your zero-first non-empty integer array example looks like this in Haskell, right?
That's a complete function that somehow manages to work without pulling in NPM dependencies. The best JavaScript minds of our generation remain baffled.> The Person/Wine example is a pointless strawman
> I didn't give practical examples to save space, obviously, it was just to disambiguate what I meant.
So when you use illustrative examples, it is to "disambiguate what you meant" (huh?), and when I do it, they're "pointless strawmen". A little hypocritical, no?
> a bit ignorant
Honestly, I don't think you know what you're talking about at all. You clearly hadn't even read my comment when you started replying with Python and TS examples... that were already in my comment.
It also really sounds like you're using string literals to type input without properly parsing it, which is just a terrible idea. Haskell's type system is designed precisely to protect you from this sort of mistake. [0] No, you're not always going to get what you expect. No, your JS program will never let you know that's the case. No, a sane type system does not require mainlining runtime parser libraries from the biohazardous oceans of NPM. A schema in Haskell is going to be significantly shorter and sounder than anything in Zod, and you don't need a library for it.
As I said above, TS' type system makes sense for a type system bolted onto a dynamic language post facto. TS needs to more tightly link (even mildly conflate) values and types, since it needs to do a lot of clever narrowing to figure out what mad ball of JS it is dealing with at any given time. Haskell does not operate under any such constraint.
> I don't see a productive continuation to this discussion.
Phew. Timesaver.
Of course the irony of all this is that I use TS daily, and Haskell quite rarely.
[0] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...