Closed rowanG077 closed 3 years ago
You gave n <= Max (n + 1) 1
as a constraint of foo
in that example. Is this a typo?
@alex-mckenna I think the title of the issue is the typo :)
We could hardcode it here:
The proper solution would probably be to introduce some interval logic. Which sounds like fun to implement, but also easy to mess up :-)
@martijnbastiaan, it's mentioned again in the non-code line below though.
The 1 <= Max (n + 1) 1 on foo should be solvable with this plugin. But an error occurs:
Aha, right! The error mentions Couldn't match type ‘n GHC.TypeNats.<=? Max (n + 1) 1’
again, so let's wait for @rowanG077 ! :-)
Ah indeed this is a typo... I guess when reducing my example to bare minimum I made this somehow. But both 1 <= Max (n + 1) 1
and n <= Max (n + 1) 1
should be solvable. But this issue is about the former case.
Actually, what needs to happen is that we should do a partial solve. Looking at the type-checker trace, I see that ghc-typelits-extra
reduced the Max
already, and it's now trying to solve: 1 <= n + 1
(or n <= n + 1
): which it can't. However, ghc-typelits-natnormalise
can!
We should detect that we did make the problem "smaller", and tag the wanted as solved, but emit a new wanted for the "smaller" problem. We have to be careful not to throw the type-checker into an infinite loop though.
A partial solve isn't necessary for the "simpler" case I think. 1 <= Max (n + 1) 1
should be solvable outright by the plugin. In fact this plugin already has machinery builtin that recognizes the general case of p <= Max n p
:
But the max constraint is simplified away before that point in the mergeMax
function.
I guess this is done to be able to solve constraints like Max (n + 1) 1 ~ 1 + n
?
The more complex case of n <= Max (n + 1) 1
would need a partial solve. But I would say this is out of scope for this issue.
Fixed with the release of version 0.4.1: https://hackage.haskell.org/package/ghc-typelits-extra-0.4.1
While working on safe index pull request I ran into this problem.
Consider this code:
The
1 <= Max (n + 1) 1
onfoo
should be solvable with this plugin. But an error occurs:The following works though:
This is an issue when using dependently typed folds where
Max
is used in things like theAResult
andMResult
types.