fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

use incomplete types in match cases (when possible)

Open michaellilltokiwa opened this issue 3 months ago • 3 comments

example diff:

diff --git a/modules/base/src/io/buffered/reader.fz b/modules/base/src/io/buffered/reader.fz
index 212314daf..6c98bfd57 100644
--- a/modules/base/src/io/buffered/reader.fz
+++ b/modules/base/src/io/buffered/reader.fz
@@ -79,7 +79,7 @@ is
       debug: buffer.buffered = 0
   =>
     match rh.read buffer.available.as_i32
-      a array u8 =>
+      a array =>
         match buffer.enqueue a
           unit => unit
           e error => e
diff --git a/modules/base/src/io/file/use.fz b/modules/base/src/io/file/use.fz
index 56607c691..a49f75042 100644
--- a/modules/base/src/io/file/use.fz
+++ b/modules/base/src/io/file/use.fz
@@ -54,7 +54,7 @@ public use(R type, file_name String, m mode.val, code ()-> outcome R) outcome R
   read_handler(desc File_Descriptor) : io.Read_Handler is
     public redef read(count i32) choice (array u8) io.end_of_file error =>
       match fuzion.sys.fileio.read desc count.as_u64
-        a array u8 => if a.is_empty then io.end_of_file else a
+        a array => if a.is_empty then io.end_of_file else a
         e error => e
 
   # definition of write handler for file
diff --git a/modules/http/src/http/Message.fz b/modules/http/src/http/Message.fz
index b102c4a53..944a340b8 100644
--- a/modules/http/src/http/Message.fz
+++ b/modules/http/src/http/Message.fz
@@ -43,7 +43,7 @@ public Message ref is
   public bytes Sequence u8 =>
     # NYI: BUG: read fully
     (start_line + header.as_string + crlf).utf8 ++ (match (body.read 1E6)
-                                                a array u8 => a
+                                                a array => a
                                                 * => [])
 
   # String representation of the message header
@@ -105,7 +105,7 @@ module:public body_reader(
     public redef read(count i32) choice (array u8) io.end_of_file error =>
 
       res choice (array u8) io.end_of_file error := match (io.buffered LM).reader.env.read count
-        c array u8 =>
+        c array =>
           (io.buffered LM).reader.env.discard c.length
           # decrease remaining if reader has a size limit
           if reader_size >= 0
diff --git a/tests/base16/base16_test.fz b/tests/base16/base16_test.fz
index 57051c7be..3ff771507 100644
--- a/tests/base16/base16_test.fz
+++ b/tests/base16/base16_test.fz
@@ -67,14 +67,14 @@ base16_test is
       plain, code_expected := tup
       code_actual := match plain
                         str String   => encodings.base16.encode_to_string str.utf8.as_array
-                        arr array u8 => encodings.base16.encode_to_string arr
+                        arr array => encodings.base16.encode_to_string arr
       out :=
         if code_actual = code_expected
           outcome "ok"
         else
           plain_str := match plain
                          str String   => str
-                         arr array u8 => $arr
+                         arr array => $arr
           error "encode '$plain_str' produced '$code_actual' but should have been '$code_expected'"
     else
       if results ∀ (.ok)
@@ -110,7 +110,7 @@ base16_test is
                   outcome "ok"
                 else
                   error "decoding $code produced '{String.from_bytes actual}' but should have been '$str'"
-              arr array u8 =>
+              arr array =>
                 if arr.length=actual.length && ((arr.zip actual a,b->a=b) ∀ id)
                   outcome "ok"
                 else
@@ -150,6 +150,6 @@ base16_test is
   for t in broken_enc do
     yak "$t: "
     say (match encodings.base16.decode_str t
-        arr array u8 => String.type.from_bytes arr
+        arr array => String.type.from_bytes arr
         e error => e.as_string)
   say ""
diff --git a/tests/base32/base32_test.fz b/tests/base32/base32_test.fz
index 748e11ec9..8253dc61b 100644
--- a/tests/base32/base32_test.fz
+++ b/tests/base32/base32_test.fz
@@ -69,14 +69,14 @@ base32_test is
       plain, code_expected := tup
       code_actual := match plain
                         str String   => encodings.base32.encode_to_string str.utf8.as_array
-                        arr array u8 => encodings.base32.encode_to_string arr
+                        arr array => encodings.base32.encode_to_string arr
       out :=
         if code_actual = code_expected
           outcome "ok"
         else
           plain_str := match plain
                          str String   => str
-                         arr array u8 => $arr
+                         arr array => $arr
           error "encode '$plain_str' produced '$code_actual' but should have been '$code_expected'"
     else
       if results ∀ (.ok)
@@ -112,7 +112,7 @@ base32_test is
                   outcome "ok"
                 else
                   error "decoding $code produced '{String.from_bytes actual}' but should have been '$str'"
-              arr array u8 =>
+              arr array =>
                 if arr.length=actual.length && ((arr.zip actual a,b->a=b) ∀ id)
                   outcome "ok"
                 else
@@ -156,6 +156,6 @@ base32_test is
   for t in broken_enc do
     yak "$t: "
     say (match encodings.base32.decode_str t
-        arr array u8 => String.type.from_bytes arr
+        arr array => String.type.from_bytes arr
         e error => e.as_string)
   say ""
diff --git a/tests/base32hex/base32hex_test.fz b/tests/base32hex/base32hex_test.fz
index 2bced3f03..c0f817045 100644
--- a/tests/base32hex/base32hex_test.fz
+++ b/tests/base32hex/base32hex_test.fz
@@ -69,14 +69,14 @@ base32hex_test is
       plain, code_expected := tup
       code_actual := match plain
                         str String   => encodings.base32hex.encode_to_string str.utf8.as_array
-                        arr array u8 => encodings.base32hex.encode_to_string arr
+                        arr array => encodings.base32hex.encode_to_string arr
       out :=
         if code_actual = code_expected
           outcome "ok"
         else
           plain_str := match plain
                          str String   => str
-                         arr array u8 => $arr
+                         arr array => $arr
           error "encode '$plain_str' produced '$code_actual' but should have been '$code_expected'"
     else
       if results ∀ (.ok)
@@ -112,7 +112,7 @@ base32hex_test is
                   outcome "ok"
                 else
                   error "decoding $code produced '{String.from_bytes actual}' but should have been '$str'"
-              arr array u8 =>
+              arr array =>
                 if arr.length=actual.length && ((arr.zip actual a,b->a=b) ∀ id)
                   outcome "ok"
                 else
@@ -156,6 +156,6 @@ base32hex_test is
   for t in broken_enc do
     yak "$t: "
     say (match encodings.base32hex.decode_str t
-        arr array u8 => String.type.from_bytes arr
+        arr array => String.type.from_bytes arr
         e error => e.as_string)
   say ""
diff --git a/tests/base64/base64_test.fz b/tests/base64/base64_test.fz
index 8e36f7ca2..117e98f2f 100644
--- a/tests/base64/base64_test.fz
+++ b/tests/base64/base64_test.fz
@@ -73,14 +73,14 @@ base64_test is
       plain, code_expected := tup
       code_actual := match plain
                         str String   => encodings.base64.encode_to_string str.utf8.as_array
-                        arr array u8 => encodings.base64.encode_to_string arr
+                        arr array => encodings.base64.encode_to_string arr
       out :=
         if code_actual = code_expected
           outcome "ok"
         else
           plain_str := match plain
                           str String   => str
-                          arr array u8 => $arr
+                          arr array => $arr
           error "encode '$plain_str' produced '$code_actual' but should have been '$code_expected'"
     else
       if results ∀ (.ok)
@@ -116,7 +116,7 @@ base64_test is
                   outcome "ok"
                 else
                   error "decoding $code produced '{String.from_bytes actual}' but should have been '$str'"
-              arr array u8 =>
+              arr array =>
                 if arr.length=actual.length && ((arr.zip actual a,b->a=b) ∀ id)
                   outcome "ok"
                 else
@@ -157,6 +157,6 @@ base64_test is
   for t in broken_enc do
     yak "$t: "
     say (match encodings.base64.decode_str t
-        arr array u8 => String.type.from_bytes arr
+        arr array => String.type.from_bytes arr
         e error => e.as_string)
   say ""
diff --git a/tests/base64url/base64url_test.fz b/tests/base64url/base64url_test.fz
index c864c9ab6..c6daf0e62 100644
--- a/tests/base64url/base64url_test.fz
+++ b/tests/base64url/base64url_test.fz
@@ -73,14 +73,14 @@ base64url_test is
       plain, code_expected := tup
       code_actual := match plain
                         str String   => encodings.base64url.encode_to_string str.utf8.as_array
-                        arr array u8 => encodings.base64url.encode_to_string arr
+                        arr array => encodings.base64url.encode_to_string arr
       out :=
         if code_actual = code_expected
           outcome "ok"
         else
           plain_str := match plain
                           str String   => str
-                          arr array u8 => $arr
+                          arr array => $arr
           error "encode '$plain_str' produced '$code_actual' but should have been '$code_expected'"
     else
       if results ∀ (.ok)
@@ -116,7 +116,7 @@ base64url_test is
                   outcome "ok"
                 else
                   error "decoding $code produced '{String.from_bytes actual}' but should have been '$str'"
-              arr array u8 =>
+              arr array =>
                 if arr.length=actual.length && ((arr.zip actual a,b->a=b) ∀ id)
                   outcome "ok"
                 else
@@ -157,6 +157,6 @@ base64url_test is
   for t in broken_enc do
     yak "$t: "
     say (match encodings.base64url.decode_str t
-        arr array u8 => String.type.from_bytes arr
+        arr array => String.type.from_bytes arr
         e error => e.as_string)
   say ""
diff --git a/tests/reg_issue3362/reg_issue3362.fz b/tests/reg_issue3362/reg_issue3362.fz
index 2b650b48d..c236759a0 100644
--- a/tests/reg_issue3362/reg_issue3362.fz
+++ b/tests/reg_issue3362/reg_issue3362.fz
@@ -44,7 +44,7 @@ reg_issue3362 is
       plain_expected, code := tup
       out :=
         match dummy_decode code.utf8.as_array
-          arr array u8 =>
+          arr array =>
             plain_actual := String.type.from_bytes arr
             if plain_actual != plain_expected     # 1. should flag an error: `choice String (array u8)` is not assignable to `property.equatable`
               error "decoding $code produced '$plain_actual' but should have been '$plain_expected'"

@tokiwa-software/developers Usually I find this easier to read. Your opinions?

michaellilltokiwa avatar Sep 11 '25 08:09 michaellilltokiwa

I don't find this easier to read. Just personal preference I think. But if you'd ask me I'd also remove type inference in favor of specifying types everywhere.

maxteufel avatar Sep 11 '25 08:09 maxteufel

If I know what the type is, especially when it is long, like s Sequence (choice some.nested.type some.other.type), I'd I find it easier to read without it. But in case I need the type and have to search for it, this would be less helpful.

simonvonhackewitz avatar Sep 12 '25 15:09 simonvonhackewitz

I think the type is usually clear from the context, no need to include the type parameters unless this results in ambiguity.

fridis avatar Sep 23 '25 14:09 fridis