I am wondering about the MonoMaybe
type family from the monad-validation
Haskell library written by Alexis King. Its definition is as follows (ignoring strictness):
{-# LANGUAGE GADTs, DataKinds #-}
data MonoMaybeS = SMaybe | SJust
data MonoMaybe (s :: MonoMaybeS) a where
MNothing :: MonoMaybe 'SMaybe a
MJust :: forall s a. a -> MonoMaybe s a
This is analogous to Maybe
, but the type forall s. MonoMaybe s A -> MonoMaybe s B
enforces the invariant that the function is "monotonically increasing", in that it can only output MNothing
when given MNothing
, by parametricity. However, usual parametricity allows one to reason about universal quantification on the universe, while here s
has type MonoMaybeS
(which in GHC Haskell is "promoted" to the type level by the DataKinds
extension).
Questions: how can we analyse the above? Is there a type theory in which one can define an indexed type family like above and prove an equivalence between $\forall s. \text{MonoMaybe}\ s\ A \to \text{MonoMaybe}\ s\ B$ and the subtype of $\text{Maybe}\ A \to \text{Maybe}\ B$ on the monotonically increasing functions? Can e.g. parametric cubical type theory à la Cavallo & Harper do this?
I have the following geometric intuition for the total space of $\lambda s. \text{MonoMaybe}\ s\ A$:
The indexing type $\text{MonoMaybeS}$ behaves as a sort of abstract interval (in particular one is not able to case split on it) which seems like it might have to do with bridge types.
forall s. MonoMaybe s a -> MonoMaybe s b
do you meanforall a b s. MonoMaybe s a -> MonoMaybe s b
? Surely when you restrict to fixed and inhabitedb
it is easy to output whatever you like. Or maybe you meanforall a b s. (a -> b) -> MonoMaybe s a -> MonoMaybe s b
? $\endgroup$a
andb
are arbitrary types here. Theconst MNothing
function does not type-check at that type. $\endgroup$forall a b s. MonoMaybe s a -> MonoMaybe s b
, right? If this is the case, why do you writeforall s
but notforall a b
? (Is this Haskell imposing dumb restrictions on dependent types?) $\endgroup$forall s. MonoMaybe s A -> MonoMaybe s B
for given typesA
andB
. TakeA = Bool
andB = Bool
if you like. $\endgroup$