Hacker News new | past | comments | ask | show | jobs | submit login

You can get that with ad hoc structural typing or by transforming into canonical nominal types that contain the subset of data you care about.

I’m not sure what these comments are arguing against, but it’s not compile-time analysis.




Thank $DEITY that impracticality is always because you’re not using the One True Static Typing School!

Seriously: you’re describing a feature that only exists in a small subset of languages and only a small subset of contexts at that. OCaml and Go do this but not for data, just for methods.


Absolutely. I wish I could structurally type a db query function in every statically typed language that doesn’t have it. Instead I end up with the challenge of coming up with the smallest number of (what is essentially) User1, User2, etc. and hope my queries and subqueries can always fill one of the existing shapes which is a significant pain point.

The language used in this thread so far has made it seem like runtime specs are the solution to this “only care about part of the bag” problem rather than what I consider a general feature of dynamic typing that certainly can be expressed statically as well.


I can’t parse that second paragraph. Can you elaborate?

Runtime specs absolutely also validate. And you can run them at test time. And you can put arbitrary code in them if you want. And sometimes you can statically validate them.

What I’m saying is you get ad hoc structural typing on everything, including data, which you’ve already said is a good thing, so I’m not sure what we’re arguing about or if we’re even arguing :)

EDIT: ah! You edited the paragraph. Simple question: where does this ideal static typing thing ship? Like, how do I do this on my machine right now? What package do I install?


If I could go back, I would’ve rephrased my original post so that it didn’t seem like it existed just to contradict the upstream posts.

People were talking about using runtime specs to annotate and validate the subset of information a function may care about. Which is certainly something I wish I could do in more languages, though ideally as much at compile time as possible.

Of course, runtime specs in Clojure let you make more assertions than just structure, so structural typing as seen in TypeScript, for example, certainly don’t go all the way. It just helps address what I thought was being discussed.

What is the ideal middleground? I think one possibility would be if Clojure was statically typed to begin with yet had the syntax of spec/schema.

Though I’m not sure we’re talking about the same thing anymore.


We're not. But: good news: people are experimenting with verifying specs at compile time! And since specs come with quickcheck built in, you get a lot of "free" (in developer hours) "compile time" (actually: development time) verification. I appreciate that is not the same thing as a proof system :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: