rtulip / haystack

Haystack is a compiled, statically typed, stack-based language with opt-in variable assignment.
MIT License
25 stars 2 forks source link

Unit Type #146

Closed rtulip closed 1 year ago

rtulip commented 1 year ago

It will be useful down the line to have a unit type, representing no change to the stack. To be consistent with the rest of the syntax, this should probably be the empty stack: []

This will be useful for something like: Result<[] String> down the line. Additionally, if the goal is to eventually have sum-types, we'll need a way to represent pure labels.

This would be the first zero sized type in Haystack, which means there's a bunch of cases that need to be handled.

  1. How is a type marked as zero sized?
  2. Can you define other zero sized types?

Eg. would the following struct compile?

struct EmptyPair {
    []: first
    []: second
}
rtulip commented 1 year ago

By adding tuple support, the empty tuple can now be used as a unit type.

There isn't a way to mark a type as zero sized (yet). You can create new zero sized types, exactly as above. There are now some bugs with zero sized types, but those are going to be fixed over time.