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 support for linear types. #70

Merged
merged 3 commits into from May 26, 2022
Merged

Add support for linear types. #70

merged 3 commits into from May 26, 2022

Conversation

sellout
Copy link
Member

@sellout sellout commented May 12, 2022

This doesn't yet take advantage of the linear optimizations, but it does allow
us to categorify linear functions.

It adds a linear-base integration, because nothing in base uses linear-types, so
we need something to test it with.

@sellout sellout force-pushed the linear branch 3 times, most recently from 443043f to 2645778 Compare May 14, 2022 00:18
@sellout sellout force-pushed the linear branch 6 times, most recently from 61a5d57 to 45769a7 Compare May 20, 2022 09:43
@sellout sellout force-pushed the linear branch 6 times, most recently from 077dea4 to 98c35c1 Compare May 24, 2022 02:40
@sellout sellout requested review from wavewave and zliu41 May 24, 2022 02:40
@sellout sellout marked this pull request as ready for review May 24, 2022 02:40
@wavewave
Copy link
Member

Would you add some expanded explanation on the meaning of "support for linear types"? :-) Having that description in this PR's description message (and commit message as it automatically adds) is fine for me. Thanks.

@sellout
Copy link
Member Author

sellout commented May 24, 2022

Would you add some expanded explanation on the meaning of "support for linear types"? :-)

Whoops, I actually meant to add this to the README. I'll still update the readme before merging, but tl;dr for now:

https://arxiv.org/abs/2103.06195v1 is the goal – targeting symmetric monoidal categories instead of cartesian closed categories (when possible). This change however is just the first step, which merely allows us to interpret linear functions as if they weren't linear. The follow-up to this will be to preserve that linearity through the plugin.

We've been talking about adding this for like a year, but now I actually have a category in a project that isn't cartesian closed, so I'm finally motivated.

This doesn't yet take advantage of the linear optimizations, but it does allow
us to categorify linear functions.

It adds a linear-base integration, because nothing in base uses linear-types, so
we need _something_ to test it with.
Unfortunately, I don't think there's a reasonable way to conditionalize the
linear-base-integration packages until Cabal 3.8 is released. Once nix-flake
integration (#66) is merged, we can perhaps do it for _those_ builds.
Copy link
Member

@wavewave wavewave left a comment

Choose a reason for hiding this comment

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

one small conditional compilation minimization request.
This looks great to me otherwise.

[Plugins.Type _mult, Plugins.Type _cat, Plugins.Type _a] -> pure Nothing
[Plugins.Type _mult, Plugins.Type _cat] -> pure Nothing
[Plugins.Type _mult] -> pure Nothing
[] -> pure Nothing
Copy link
Member

Choose a reason for hiding this comment

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

From this to line 544, it's the same as non-linear version. we had better minimize conditional compilation part.

Copy link
Member Author

Choose a reason for hiding this comment

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

This can be difficult with Ormolu. They've changed the way CPP is handled a few times, but I think the current approach is that CPP directives are treated as comments, and then the module is formatted.

Generally, this means that putting directives around top-level definitions works just fine. Other cases may work, but are more fragile. Here, shrinking the directives to only cover some of the case alternatives causes a parse error. I'm not sure exactly why, as it seems like treating the directives as comments should allow that to work. But I'm guessing there's some subtlety in the CPP handling that I'm missing.

Copy link
Member

Choose a reason for hiding this comment

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

I see. yeah. I was often bitten by ormolu and CPP incompatibility. If not easily fixable, please disregard my suggestion.

@wavewave wavewave self-requested a review May 26, 2022 03:52
@sellout sellout merged commit d8dc110 into master May 26, 2022
@sellout sellout deleted the linear branch May 26, 2022 04:15
@zliu41
Copy link
Member

zliu41 commented May 26, 2022

It's neat that no change needs to be made to categorify!

@sellout
Copy link
Member Author

sellout commented May 26, 2022

It's neat that no change needs to be made to categorify!

No changes yet. Making the linear interpretation simpler than the standard one will certainly involve changes there.

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.

None yet

3 participants