I have a bunch of complicated type level functions that evaluate to things like:
(If (EqNat n 2)
1
(If (EqNat n 1)
2
(If (EqNat n 0) 3 0)))
Now obviously in this case this expression is a KnownNat
. More
generally we may say:
forall (c :: * -> Constraint) (p :: Bool) a b .
(c a, c b) => c (If p a b)
Is there a way to teach GHC to infer this?
Edit: @chi noted that in some cases this is solvable with GADTs but my particular case is this one:
module M1 (C(..)) where
type familiy NestedIfs (n :: Nat) :: Nat
type NestedIfs n = <<complex nested ifs like the above that evals to literals>>
class C a (n :: Nat) where
f :: KnownNat n => a -> NestedIfs n -> Bool
and then
module M2 () where
import M1
instance C Int n where
f = ...require that KnownNat (NestedIfs n)...
NestedIfs
is not accessible to M2
but maybe GHC should be able to
infer that forall n . KnownNat n => KnownNat (NestedIfs n)
from the
general inference I mention above.