-
Notifications
You must be signed in to change notification settings - Fork 54
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
Recursive types #1894
Recursive types #1894
Conversation
I just realized I need to rule out types like |
@byorgey Ha, thanks, I will try this out! 👍 I noticed you needed the VSCode syntax updated and I see the |
6bdfcb4
to
c448db6
Compare
This should be ready now. In theory we ought to have a device that provides the capability to use recursive types, but that will require some refactoring of the requirements analysis code so I opted to leave it for another PR: see #1898. |
@@ -163,7 +163,7 @@ primitiveTypeNames = "Cmd" : baseTypeNames | |||
|
|||
-- | List of keywords built into the language. | |||
keywords :: [Text] | |||
keywords = T.words "let in def tydef end true false forall require requirements" | |||
keywords = T.words "let in def tydef end true false forall require requirements rec" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be followed up with updating the editor configurations (swarm-mode.el
, swarm.vim
etc)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I will update that shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the emacs and vim configs to add a rec
keyword. I was not sure how to update the vscode config (and it seems like @xsebek is in the middle of updating it anyway).
c448db6
to
1aec278
Compare
1aec278
to
faeb898
Compare
Implements recursive types. Example:
As discussed at #154, this uses the syntax
rec x. F(x)
to define the typex
which is a solution tox = F(x)
. However, unlike the discussion there, I ended up going with equirecursive types (so a recursive type is equal to its unfolding). For example, as you can see above, if we have a value of typeList a
(defined asrec l. Unit + a * l
), then it actually has the equivalent typeUnit + a * List a
, so we can simply do acase
on it, without having tounroll
first. This actually turned out to be easier to implement (and it is cooler).There are multiple built-in functions that conceptually return a list but currently do something different (like return a fold, or take an index and return a single element, etc.) We should consider changing them to actually return lists, but that should definitely be in a separate PR.
Closes #154.