News for hackers. Stuff that matters.
Re:Moving Beyond Type Systems by librasteve on Saturday June 01, 2024 @03:07AM (#40543561)
in the OP example, this is considered bad

  let x: string = "hello world";
  x = 32;  #type error
however, a well designed strong typesystem should be able to compose types to allow this if desired by the coder (eg. to read in a column of numbers from a csv)

  my $forty-two = 42 but 'forty two';
  say $forty-two+33;    # OUTPUT: «75␤» 
  say $forty-two.^name; # OUTPUT: «Int+{<anon|1>}␤» 
  say $forty-two.Str;   # OUTPUT: «forty two␤» 
Calling ^name shows that the variable is an Int with an anonymous object mixed in. However, that object is of type Str, so the variable, through the mixin, is endowed with a method with that name, which is what we use in the last sentence.

https://docs.raku.org/routine/but

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
Re:Moving Beyond Type Systems by sparkie on Saturday June 01, 2024 @04:13PM (#40548730)
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