Re:Moving Beyond Type Systems
by 3836293648 on Saturday June 01, 2024 @10:27AM
(#40546029)
It's bad because of the explicit signature. If the signature had been `string | int` thenn it's a type system feature
[ Parent
| on HN ]
Yeah, we can consider `string`, `int` to both be subtypes of `string | int`, and `string & int` to be a subtype of both `string`, `int`.
There are some problems with doing so though, such as inferring the types, but they can be mostly mitigated by giving types a polarity, as Dolan introduced in Algebraic Subtyping[1]
[1]:https://www.cs.tufts.edu/~nr/cs257/archive/stephen-dolan/the...
Re:Moving Beyond Type Systems
by librasteve on Sunday June 02, 2024 @02:54PM
(#40556422)
good point - I am just a little reluctant to swallow that a strong type system is intended to stop us accidentally assigning a number to a string var - raku is an interesting case since the strong types in raku (aka perl6) were crafted so that the typical (untyped) perl case of
my $x = "1";
print $x+1; #2
print $x.1; #'11' ('.' is perl for string concatenate)
so in raku, untyped, thats my $x = "1";
say $x+1; #2
say $x~1; #'11' ('~' is raku for string concatenate)
ok, but raku can be strongly typed too, so how to graduate to that without throwing out the first draft my IntStr $x = <1>; ('<>' is raku for Allomorph literal)
say $x+1; #2
say $x~1; #'11'
just reach for the IntStr type (it's built in and has a literal syntax sugar)the main idea for gradual typing to allow code to be evolved by adding types over time without necessarily knowing all the types you are going to settle on before you start