Convincing GHC that `Maybe Void` is a unit type
I have a type family IfEq (n :: Nat) (m :: Nat) o
that evaluates to o
or Void
depending on wether n :== m
. Since Maybe Void
is only inibited by Nothing
I should be able to define a function Maybe (IfEq nmo) -> Maybe o
but I can't figure it out.
Follow up: Can this generalized from the Maybe
monad to a more general type? (eg. all MonadPlus
s)
EDIT: I had initially rolled my own Nat
but (thank's to @chi) with the GHC Nat
kind KnownNat
constrait it pretty straightforward to do what I describe above. However GHC can not infer KnownNat a => KnownNat (1+a)
which is imperative to me so I am back at square 1.
尝试类似
foo :: forall n m o . (KnownNat n, KnownNat m) =>
IfEq n m o -> Maybe o
foo x = case sameNat (Proxy :: Proxy n) (Proxy :: Proxy m) of
Just Refl -> Just x
Nothing -> Nothing
链接地址: http://www.djcxy.com/p/43148.html
上一篇: 推断泛型类型的嵌套静态泛型函数