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 sum types to the language #46

Closed
byorgey opened this issue Sep 24, 2021 · 0 comments · Fixed by #224
Closed

Add sum types to the language #46

byorgey opened this issue Sep 24, 2021 · 0 comments · Fixed by #224
Assignees
Labels
C-Project A larger project, more suitable for experienced contributors. L-Language design Issues relating to the overall design of the Swarm language. S-Moderate The fix or feature would substantially improve user experience.

Comments

@byorgey
Copy link
Member

byorgey commented Sep 24, 2021

Somehow I added product types but haven't gotten around to adding sum types yet!

@byorgey byorgey added C-Moderate Effort Should take a moderate amount of time to address. S-Moderate The fix or feature would substantially improve user experience. L-Language design Issues relating to the overall design of the Swarm language. C-Project A larger project, more suitable for experienced contributors. and removed C-Moderate Effort Should take a moderate amount of time to address. labels Sep 24, 2021
@byorgey byorgey self-assigned this Oct 13, 2021
@byorgey byorgey mentioned this issue Oct 13, 2021
@mergify mergify bot closed this as completed in #224 Oct 16, 2021
mergify bot pushed a commit that referenced this issue Oct 16, 2021
Adds sum types (e.g. `int + bool`) along with constants `inl : a -> a + b`, `inr : b -> a + b`, and `case : a + b -> (a -> c) -> (b -> c) -> c`.

I considered whether to automatically wrap the arguments to `case` in `delay`, like the arguments to `if`, but they are already functions anyway so we get a lot of laziness for free.  It would only make a difference if you wrote something like `case foo (let x = blah in \y. ...) (...)` in which case the `let x = blah` is going to be evaluated eagerly, *before* we know which branch we are going to take.  I don't think it's worth bothering about.  In the normal case that you write `case foo (\y. ...) (\z. ...)` then only one of the two functions gets run at all, without us having to do anything special with `delay`.

I also considered whether to make special syntax for case expressions, like `case foo of { inl x -> ... ; inr y -> ... }` but doing it as a simple built-in function is both easier to implement and feels like it fits better with the aesthetic of the language so far.

Closes #46 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Project A larger project, more suitable for experienced contributors. L-Language design Issues relating to the overall design of the Swarm language. S-Moderate The fix or feature would substantially improve user experience.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant