haskell / mtl

The Monad Transformer Library
http://www.haskell.org/haskellwiki/Monad_Transformers
Other
360 stars 63 forks source link

Make MonadCont instance for ContT polykinded #129

Closed Icelandjack closed 2 years ago

Icelandjack commented 2 years ago
type ContT :: k -> (k -> Type) -> Type -> Type

instance MonadCont (ContT @Type r m)

The MonadCont instance for ContT is unnecessarily restricted to types when it can be polykinded

instance MonadCont (ContT @k r m) where
  callCC :: ((a -> ContT r m b) -> ContT r m a) -> ContT r m a
  callCC cont = ContT \c -> runContT (cont \x -> ContT \ _ -> c x) c

This allows deriving

type Term :: S -> (S -> Type) -> Type

type    ContTerm :: S -> Type -> Type
newtype ContTerm s a = ContTerm ((a -> Term s r) -> Term s r)
  deriving (Functor, Applicative, Monad, MonadCont)
  via ContT @S r (Term s)

The kind of ContT should also be made specifiable: forall k. k -> (k -> Type) -> Type -> Type rather than inferrable forall {k}. .. as it is now.

kozross commented 2 years ago

I don't object to making MonadCont have more polykinded instances.

Qqwy commented 2 years ago

This seems like a good idea.

Are there any downsides to making this change? I cannot think of any obvious ones at least.