Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes however I get that in TS and Rust while also having stronger type guarantees. I don't think pattern matching is an alternative to static types, it's a supplement.


Well, I suppose to each their own. I use languages with and without static typing. I love Ada the most though, because the way you define types is very different from the most widespread way. In Ada, you define the range.

Examples:

  type Day is
    (Monday,
     Tuesday,
     Wednesday,
     Thursday,
     Friday,
     Saturday,
     Sunday);
  subtype Business_Day is Day range Monday .. Friday;
  subtype Weekend_Day is Day range Saturday .. Sunday;
  subtype Dice_Throw is Integer range 1 .. 6;

  type Arr_Type is array (Integer range <>) of Character;
  type Color  is (White, Red, Yellow, Green, Blue, Brown, Black);
  type Column is range 1 .. 72;
  type Table  is array(1 .. 10) of Integer;

  type Device_Register is range 0 .. 2**5 - 1 with Size => 5;
  type Commands is (Off, On);
  type Commands2 is new Integer with
    Static_Predicate => Commands in 2 | 4;


Rust, sure. Love me some Rust.

Typescript's type system isn't sound and you can still get runtime errors. (Type systems should be bomb-proof or just get out of the way.)


Is there pattern matching in TS function heads?




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

Search: