logoalt Hacker News

ossopitetoday at 10:31 AM2 repliesview on HN

I'm not convinced it really works well in typescript. the lack of nominal types requires you to remember some pretty hacky incantations if you want something like a newtype wrapping a primitive type

my experience is that ocaml is more powerful than rust for enforcing this sort of type safety, because you have gadts that give you more expressive power, and polymorphic variants and object types (record row types) that give you more convenience. and the module system and functors of course.

you also avoid some abstraction limitations/difficulties that come from the rust borrow checker for places where garbage collection is just fine


Replies

cyberpunktoday at 10:42 AM

It really feels like we’re solving the wrong problem sometimes. If a bad type can crash your application, sure, type safety is one answer but I have to admit I like the erlang approach; if something unexpected happens crash the process (not os process, erlang process) which has a very small blast radius on a well architected system (maybe doesn’t even fail the individual request that caused it). I wish more languages had this let it crash philosophy, it really allows for writing code exclusively for the happy path, safe in the knowledge that a -1 where a “string” should be isn’t going to take down production.

Somehow, it feels like a better solution than these complicated type systems. Does any other language do this outside BEAM?

show 4 replies
jbreckmckyetoday at 11:10 AM

> some pretty hacky incantations

  type NewType<T, Name> = T & { readonly __brand: Name };
I don't really see a big problem here?
show 1 reply