3 ms·
I've found that pattern matching in the function head and guards get you most of the way there.
by cpursley 3y ago
I've found that pattern matching in the function head and guards get you most of the way there.
- satvikpendem 3y agoYes 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.
- weatherlight 3y agoRust, 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.)
- johnisgood 3y agoWell, 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;
- cpursley 3y agoIs there pattern matching in TS function heads?