Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openStructOption & structOption #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GTrunSec
Copy link

@GTrunSec GTrunSec commented Nov 8, 2023

The field type must be included within the {...} structAttrs.
If the field type exists within {...} structAttrs

contrast with:

(openStruct "option" {a = string; b = int; c = attrs any;}) {a = "x"; b = 5; c = {}; d = "5";}
{ a = "x"; b = 5; c = { ... }; d = "5"; }

(openStruct "option" {a = string; b = int; c = attrs any;}) {a = "x"; b = 5; d = "5";}
 expected 'option'-struct, but found:
 missing required attrs<any> field 'c'

(openStructOption "option" {a = string; b = int; c = attrs any;}) {a = "x"; b = 5; d = "5";}
{ a = "x"; b = 5; d = "5"; }

@GTrunSec
Copy link
Author

GTrunSec commented Nov 9, 2023

fix the error output of either

/*
  (struct {name = string;}) { addr = "xxx"; }
  =>
    expected 'anon'-struct, but found:
    missing required string field 'name'
    unexpected struct field 'addr

  (struct {age = string;}) { addr = "xxx"; }
   =>
    expected 'anon'-struct, but found:
    missing required int field 'age'
    unexpected struct field 'addr'


  either (struct {name = string;}) (struct { age = int; }) { addr = "xxx"; }
  =>
      expected type 'either<anon, anon>', but value '{
        addr = "xxx";
      }' is of type 'set'
 

after

(either (struct {name = string;}) (struct { age = int; })) { addr = "xxx"; }
=>
expected type 'either<anon, anon>', but found:
       missing required string field 'name'
       unexpected struct field 'addr'

       expected type 'either<anon, anon>', but found:
       missing required int field 'age'
       unexpected struct field 'addr'

Copy link
Collaborator

@blaggacao blaggacao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an option struct not better pe composed of a strict with option type?

err = "";
};
# Function to check if a field should be ignored
shouldIgnore = n: ignored || hasAttr n def;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to grok how hasAttr n def translates to the concept of "should ignore". Could you find a more suitable name?

in
if shouldIgnore n
then
if hasAttr n def
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat redundant, because it's already checked in one branch of shouldIgnore.

Maybe it's just the naming that confuses me here 😊

Ideally, the redundant branches could be unified.

Edit: for clarity I suggest you do a plain 3-branch case (if else) statement (ignored/hasattr/else)

=>
{ Inputs = { ... }; }
*/
structOption = arg:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I parse this name as an "option for a struct", but it rather is a "struct with all elements being optional".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants