serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 26 forks source link

[#265] Make SuperComposition less brittle #266

Closed treeowl closed 2 years ago

treeowl commented 2 years ago

Description

Related issues(s)

✓ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

Stylistic guide (mandatory)

treeowl commented 2 years ago

This change causes compilation failures in the benchmark suite. I tried to patch that up using an incoherent instance (to let type information flow from the result type to the second argument type):

instance {-# INCOHERENT #-} (SuperComposition x y d q, cd ~ (c -> d)) =>
         SuperComposition x y cd (c -> q) where
    (f ... g) c = (...) @x @y @d @q f (g c)
    {-# INLINE (...) #-}

For some reason, that leads to a reduction stack overflow in the benchmark, which I find extremely mysterious. It looks to me like at least one type argument gets smaller in each recursive call, and none get larger. What am I missing???

treeowl commented 2 years ago

Oh, of course, that particular instance is just wrong, because the arrows could come from the first argument. Whoops! I think it's okay to break this a little, in exchange for more stable behavior.

treeowl commented 2 years ago

Where should I put a migration guide?