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

Undocumented concepts: "type", "enum", "struct", "union" #606

Open
ThinkOpenly opened this issue Jun 24, 2024 · 4 comments
Open

Undocumented concepts: "type", "enum", "struct", "union" #606

ThinkOpenly opened this issue Jun 24, 2024 · 4 comments
Assignees

Comments

@ThinkOpenly
Copy link
Contributor

ThinkOpenly commented Jun 24, 2024

  • type
    There is no obvious documentation for the "type" keyword, although it appears early in the tutorial, then in "Usage :: Other options".
    In the tutorial, I see:

    type xlen : Int = 64
    

    Is Int (capital I) a built-in type? If not, that could be confusing.
    "type variables" is a term referenced in the first section under "The Sail Language", but this term is not defined.

  • struct
    The first appearance of the struct keyword appears in "Matching on structs". There is no documentation on its form or purpose before or after.

  • enum
    Similar story as struct.

  • union
    Same. There are some isolated references in "Scattered definitions".

@Alasdair
Copy link
Collaborator

Is Int (capital I) a built-in type? If not, that could be confusing.

In a sense. To be precise it's a built in kind, which is the type of a type, so we might say:

  • 5 : int "five has type int"
  • int : Type "int has kind Type", or "int is a type"

For something like bitvector, that is a type constructor with kind Int -> Type, means that bitvector creates a type by taking a type-level integer as an argument.

Most mainstream languages just have a single kind for all types, so don't expose this in the syntax, and very few languages have any higher-kinded polymorphism like Haskell (Sail does not have this either though) that would require distinguishing Type and Type -> Type in the syntax. Sail has this because we distinguish between integers, constraints, and 'regular types' in types (using the kinds Int, Bool, and Type).

In theory we could make this more transparent with some better kind-inference, as it should be possible to always infer kinds. Not sure how best to present this in the manual without going to deep into type theory.

@Alasdair Alasdair self-assigned this Jun 24, 2024
@Alasdair
Copy link
Collaborator

There is now documentation for enum and struct in the manual. I will add the others hopefully this week.

@Alasdair
Copy link
Collaborator

Documentation for union has been added.

There is also now kind-inference, so one can now write just type xlen = 64, which should allow some examples to be simplified.

@Alasdair
Copy link
Collaborator

I've now added a section on type synonyms and type kinds as well.

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

No branches or pull requests

2 participants