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

Preprocessing step to make sure categorify calls are in the right form #33

Open
zliu41 opened this issue Mar 12, 2022 · 0 comments
Open

Comments

@zliu41
Copy link
Member

zliu41 commented Mar 12, 2022

We use presimplifier to support partial applications of Categorify.expression hidden inside a wrapper function, like this:

preApply :: (a -> b) -> a `c` b
preApply = Categorify.expression
{-# INLINE preApply #-}

(see https://github.com/con-kitty/categorifier/blob/d72020b7f2c4534f94d7694b477e0dc8a3cb1f77/plugin/Categorifier/Test/PartialApplication.hs)

The presimplifier performs inlining, which inlines preApply and exposes Categorify.expression, whose applications are now fully saturated.

However, this approach doesn't work for slightly non-trivial cases, for example:

preApply :: (a -> b) -> a `c` b
preApply = if True then Categorify.expression else error "oops"
{-# INLINE preApply #-}

or direct partial application:

Categorify.expression . foo

Also, running the presimplifier has the disadvantage of unwanted inlining, e.g., sometimes fromIntegral is inlined and becomes fromInteger . toInteger, which may lead to categorification failures (e.g., the target category C.Cat does not support categorifying toInteger).

We should use a different approach to support (at least some) partial applications. At least Categorify.expression . foo seems easy to support.

zliu41 added a commit that referenced this issue Mar 12, 2022
See #33 for motivation
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

No branches or pull requests

1 participant