Closed RyanGlScott closed 6 years ago
I suspect this is tricky given the way type-checker plugins and closed type families interact, unfortunately. There isn't a way to directly hook into the evaluation of Replicate (k + 1) x
to make it reduce, nor a first-class way to express the required apartness constraint. In principle, a plugin could look for stuck closed type family applications and implement its own fall-through pattern-matching based on a custom apartness relation, but it's decidedly nontrivial...
I was afraid that might be the case. In any event, thanks for entertaining the idea!
Disclaimer: I don't know if GHC typechecker plugins have the power to do what I'm seeking, so if the answer is "no", feel free to close this issue. That being said, sometimes I feel
masochisticadventurous and try to do inductive-style definitions overNat
. Inevitably, I run into the sort of trouble that is exemplified in the code below:Alas,
replicateSucc
doesn't typecheck. GHC can't reduceReplicate (k + 1) x
because it's not sure ifk + 1
equals0
or not, soReplicate
gets stuck. Intuitively,k + 1
is never equal to0
, but the typechecker is sadly unaware of this fact.My question is: can we leverage the power of
ghc-typelits-natnormalise
to accomplish this? This is a bit of different territory forghc-typelits-natnormalise
, which is normally used to conclude that things are equal, but here, we want to inform the typechecker thatk + 1
is not equal to0
(and similarly,1 + k
is not equal to0
).